From 2c458e17602f5066867dbf569f6bc9b4d6351387 Mon Sep 17 00:00:00 2001 From: Nishant Srivastava Date: Fri, 29 Oct 2021 01:56:27 +0200 Subject: [PATCH 1/5] cleanup and setup publishing code --- app/build.gradle | 21 +++---- .../nisrulz/projectqreader/MainActivity.kt | 10 ++-- build.gradle | 2 +- configs/android.gradle | 32 +++++++++++ .../dependencies.gradle | 37 +++++------- configs/library.gradle | 30 ++++++++++ libconfig.gradle | 57 ------------------- qreader/build.gradle | 26 +++------ 8 files changed, 99 insertions(+), 116 deletions(-) create mode 100644 configs/android.gradle rename dependencies.gradle => configs/dependencies.gradle (51%) create mode 100644 configs/library.gradle delete mode 100644 libconfig.gradle diff --git a/app/build.gradle b/app/build.gradle index 8f8d837..3546b12 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,28 +14,24 @@ * limitations under the License. */ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: '../dependencies.gradle' +plugins { + id 'com.android.application' + id 'kotlin-android' +} + +// Apply common configs +apply from: "${rootDir}/configs/dependencies.gradle" +apply from: "${rootDir}/configs/android.gradle" android { compileSdk versions.compileSdk defaultConfig { - minSdk versions.minSdk - targetSdk versions.targetSdk - applicationId "github.nisrulz.projectqreader" versionCode versions.appVersionCode versionName versions.appVersionName testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } buildFeatures { // Enabled View Binding @@ -44,7 +40,6 @@ android { } dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') // Support implementation androidX diff --git a/app/src/main/java/github/nisrulz/projectqreader/MainActivity.kt b/app/src/main/java/github/nisrulz/projectqreader/MainActivity.kt index ddeae88..a5fd03e 100644 --- a/app/src/main/java/github/nisrulz/projectqreader/MainActivity.kt +++ b/app/src/main/java/github/nisrulz/projectqreader/MainActivity.kt @@ -148,13 +148,13 @@ class MainActivity : AppCompatActivity() { internal fun readQRCodeFromDrawable(resID: Int) { qrEader = QREader.Builder(this, object : QRDataListener { - override fun onDetected(data: String) { + override fun onDetected(data: String?) { Log.d("QREader", "Value : $data") binding.txtQrCodeInfo.post { binding.txtQrCodeInfo.text = data } } - override fun onReadQrError(exception: Exception) { - Toast.makeText(this@MainActivity, exception.localizedMessage, Toast.LENGTH_LONG) + override fun onReadQrError(exception: Exception?) { + Toast.makeText(this@MainActivity, exception?.localizedMessage, Toast.LENGTH_LONG) .show() } }).build() @@ -167,12 +167,12 @@ class MainActivity : AppCompatActivity() { // Init QREader // ------------ qrEader = QREader.Builder(this, object : QRDataListener { - override fun onDetected(data: String) { + override fun onDetected(data: String?) { Log.d("QREader", "Value : $data") binding.txtQrCodeInfo.post { binding.txtQrCodeInfo.text = data } } - override fun onReadQrError(exception: Exception) { + override fun onReadQrError(exception: Exception?) { Toast.makeText(this@MainActivity, "Cannot open camera", Toast.LENGTH_LONG).show() } diff --git a/build.gradle b/build.gradle index f49f8dd..a01442c 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { // Gradle will not find vars defined in an external file when referring to them // in the buildscript block, unless you link it from the buildscript block, too. - apply from: 'dependencies.gradle' + apply from: "${rootDir}/configs/dependencies.gradle" repositories { google() diff --git a/configs/android.gradle b/configs/android.gradle new file mode 100644 index 0000000..f089892 --- /dev/null +++ b/configs/android.gradle @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2017 Nishant Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +android { + defaultConfig { + minSdk versions.minSdk + targetSdk versions.targetSdk + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') +} \ No newline at end of file diff --git a/dependencies.gradle b/configs/dependencies.gradle similarity index 51% rename from dependencies.gradle rename to configs/dependencies.gradle index 6308cf1..0c69e67 100644 --- a/dependencies.gradle +++ b/configs/dependencies.gradle @@ -16,40 +16,33 @@ ext { versions = [ - appVersionCode : 2, - appVersionName : '1.0.1', + appVersionCode : 2, + appVersionName : '1.0.1', - minSdk : 21, - targetSdk : 31, - compileSdk : 31, + minSdk : 21, + targetSdk : 31, + compileSdk : 31, - androidGradlePlugin: '7.0.3', - kotlinVersion : '1.5.31', + appcompat : '1.0.2', + annotation : '1.2.0', + lifeycle_runtime: '2.3.1', - appcompat : '1.0.2', - annotation : '1.2.0', - - lifeycle_runtime : '2.3.1', - vision : '21.0.0', + vision : '21.0.0', ] - visionDeps = [vision: "com.google.firebase:firebase-ml-vision:$versions.vision"] - - lifecycle = [ - 'runtime': "androidx.lifecycle:lifecycle-runtime-ktx:$versions.lifeycle_runtime" - ] - androidXDeps = [ - appcompat : "androidx.appcompat:appcompat:$versions.appcompat", - annotation: "androidx.annotation:annotation:$versions.annotation" + appcompat : "androidx.appcompat:appcompat:$versions.appcompat", + annotation : "androidx.annotation:annotation:$versions.annotation", + lifecycle_runtime: "androidx.lifecycle:lifecycle-runtime-ktx:$versions.lifeycle_runtime" ] gradlePlug = [ - android: "com.android.tools.build:gradle:$versions.androidGradlePlugin", - kotlin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion", + android : "com.android.tools.build:gradle:7.0.3", + kotlin : "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31", + nexus_plugin: "com.vanniktech:gradle-maven-publish-plugin:0.18.0", ] gradlePlugins = gradlePlug.values() diff --git a/configs/library.gradle b/configs/library.gradle new file mode 100644 index 0000000..e646666 --- /dev/null +++ b/configs/library.gradle @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2017 Nishant Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: "com.vanniktech.maven.publish" + +final versionCode = 13 +final versionName = "2.2.0" + +android { + defaultConfig { + // define version + buildConfigField 'int', 'VERSION_CODE', "${versionCode}" + buildConfigField 'String', 'VERSION_NAME', "\"${versionName}\"" + + consumerProguardFiles 'consumer-proguard-rules.pro' + } +} \ No newline at end of file diff --git a/libconfig.gradle b/libconfig.gradle deleted file mode 100644 index 9595725..0000000 --- a/libconfig.gradle +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2017 Nishant Srivastava - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -// Replace nisrulz with -final group = "com.github.nisrulz" -final artifact = "qreader" -final versionCode = 13 -final versionName = "2.2.0" - -android { - defaultConfig { - // define version - buildConfigField 'int', 'VERSION_CODE', "${versionCode}" - buildConfigField 'String', 'VERSION_NAME', "\"${versionName}\"" - } -} - - -ext { - libConfig = [ - versionCode : 13, - versionName : '2.2.0', - pomUrl : 'https://github.com/nisrulz/qreader', - githubRepo : 'nisrulz/qreader', - - moduleName : 'qreader', - moduleDesc : 'Android library that uses google\'s mobile vision api and simplify the QR code reading process.', - bintrayName : 'com.github.nisrulz:qreader', - - publishedGroupId: GROUP, - developerId : POM_DEVELOPER_ID, - developerName : POM_DEVELOPER_NAME, - developerEmail : POM_DEVELOPER_EMAILID, - licenseName : POM_LICENCE_NAME, - licenseUrl : POM_LICENCE_URL, - allLicenses : [POM_ALL_LICENCES], - ] - - bintray = [ - user : BINTRAY_USER, - apikey: BINTRAY_APIKEY - ] -} \ No newline at end of file diff --git a/qreader/build.gradle b/qreader/build.gradle index 77e1a93..50e1c02 100644 --- a/qreader/build.gradle +++ b/qreader/build.gradle @@ -14,30 +14,20 @@ * limitations under the License. */ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply from: '../dependencies.gradle' -//apply from: '../libconfig.gradle' +plugins { + id 'com.android.library' + id 'kotlin-android' +} +// Apply common configs +apply from: "${rootDir}/configs/dependencies.gradle" +apply from: "${rootDir}/configs/android.gradle" +apply from: "${rootDir}/configs/library.gradle" android { compileSdk versions.compileSdk - - defaultConfig { - minSdk versions.minSdk - targetSdk versions.targetSdk - - consumerProguardFiles 'consumer-proguard-rules.pro' - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } } dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') implementation androidXDeps.annotation api vision } From e6a153085a70c27173b15f8584f8852ef7c03671 Mon Sep 17 00:00:00 2001 From: Nishant Srivastava Date: Fri, 29 Oct 2021 02:07:09 +0200 Subject: [PATCH 2/5] add info about pom config --- .gitignore | 3 --- gradle.properties | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gradle.properties diff --git a/.gitignore b/.gitignore index 8ab99ec..54b905a 100644 --- a/.gitignore +++ b/.gitignore @@ -64,9 +64,6 @@ release.properties # Ignore Gradle GUI config gradle-app.setting -# Properties -gradle.properties - # Mobile Tools for Java (J2ME) .mtj.tmp/ diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..cdd096a --- /dev/null +++ b/gradle.properties @@ -0,0 +1,27 @@ +android.enableJetifier=true +android.useAndroidX=true + +# Disable signing for generating an unsigned build +# RELEASE_SIGNING_ENABLED=false + +# QReader Configs +GROUP=com.github.nisrulz +POM_ARTIFACT_ID=qreader +VERSION_NAME=2.2.0 + +POM_NAME=qreader +POM_DESCRIPTION=Android library that uses google\'s mobile vision api and simplify the QR code reading process. +POM_INCEPTION_YEAR=2016 +POM_URL=https://github.com/nisrulz/qreader + +POM_LICENSE_NAME=The Apache Software License, Version 2.0 +POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENSE_DIST=repo + +POM_SCM_URL=https://github.com/nisrulz/qreader +POM_SCM_CONNECTION=scm:git:git://github.com/nisrulz/qreader.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/nisrulz/qreader.git + +POM_DEVELOPER_ID=nisrulz +POM_DEVELOPER_NAME=Nishant Srivastava +POM_DEVELOPER_URL=https://github.com/nisrulz/ \ No newline at end of file From 013dba43bd4aa55bc5429ce9b6dccea143862a25 Mon Sep 17 00:00:00 2001 From: Nishant Srivastava Date: Fri, 29 Oct 2021 02:10:56 +0200 Subject: [PATCH 3/5] add info about publishToMavenLocal task --- configs/library.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/library.gradle b/configs/library.gradle index e646666..e08bc27 100644 --- a/configs/library.gradle +++ b/configs/library.gradle @@ -14,6 +14,8 @@ * limitations under the License. */ +// To publish to the local maven repository on your machine (~/.m2/repository), +// run: ./gradlew publishToMavenLocal apply plugin: "com.vanniktech.maven.publish" final versionCode = 13 From 26d8ce6191bc02985b0862d46b458354a8c4facb Mon Sep 17 00:00:00 2001 From: Nishant Srivastava Date: Fri, 29 Oct 2021 02:30:40 +0200 Subject: [PATCH 4/5] unify gradle configs --- app/build.gradle | 11 ----------- build.gradle | 11 +---------- configs/all_projects.gradle | 19 +++++++++++++++++++ configs/dependencies.gradle | 3 +-- configs/library.gradle | 5 +++++ gradle.properties | 2 +- qreader/build.gradle | 16 ---------------- 7 files changed, 27 insertions(+), 40 deletions(-) create mode 100644 configs/all_projects.gradle diff --git a/app/build.gradle b/app/build.gradle index 3546b12..b0d5939 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,18 +14,7 @@ * limitations under the License. */ -plugins { - id 'com.android.application' - id 'kotlin-android' -} - -// Apply common configs -apply from: "${rootDir}/configs/dependencies.gradle" -apply from: "${rootDir}/configs/android.gradle" - android { - compileSdk versions.compileSdk - defaultConfig { applicationId "github.nisrulz.projectqreader" versionCode versions.appVersionCode diff --git a/build.gradle b/build.gradle index a01442c..a262f84 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,6 @@ */ // Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { // Gradle will not find vars defined in an external file when referring to them // in the buildscript block, unless you link it from the buildscript block, too. @@ -31,13 +30,5 @@ buildscript { } } -allprojects { - repositories { - google() - mavenCentral() - } -} -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file +apply from: "${rootDir}/configs/all_projects.gradle" \ No newline at end of file diff --git a/configs/all_projects.gradle b/configs/all_projects.gradle new file mode 100644 index 0000000..30638e6 --- /dev/null +++ b/configs/all_projects.gradle @@ -0,0 +1,19 @@ +allprojects { + repositories { + google() + mavenCentral() + } + + switch (project.name) { + case "app": apply plugin: 'com.android.application'; break + default: apply plugin: 'com.android.library'; break + } + apply plugin: 'kotlin-android' + + android { + compileSdk versions.compileSdk + } + + apply from: "${rootDir}/configs/dependencies.gradle" + apply from: "${rootDir}/configs/android.gradle" +} diff --git a/configs/dependencies.gradle b/configs/dependencies.gradle index 0c69e67..5557636 100644 --- a/configs/dependencies.gradle +++ b/configs/dependencies.gradle @@ -31,7 +31,7 @@ ext { ] - visionDeps = [vision: "com.google.firebase:firebase-ml-vision:$versions.vision"] + visionDeps = "com.google.firebase:firebase-ml-vision:$versions.vision" androidXDeps = [ appcompat : "androidx.appcompat:appcompat:$versions.appcompat", @@ -47,5 +47,4 @@ ext { gradlePlugins = gradlePlug.values() androidX = androidXDeps.values() - vision = visionDeps.values() } diff --git a/configs/library.gradle b/configs/library.gradle index e08bc27..a7701a2 100644 --- a/configs/library.gradle +++ b/configs/library.gradle @@ -29,4 +29,9 @@ android { consumerProguardFiles 'consumer-proguard-rules.pro' } +} + +dependencies { + implementation androidXDeps.annotation + api visionDeps } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index cdd096a..1cc482d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ GROUP=com.github.nisrulz POM_ARTIFACT_ID=qreader VERSION_NAME=2.2.0 -POM_NAME=qreader +POM_NAME=QReader POM_DESCRIPTION=Android library that uses google\'s mobile vision api and simplify the QR code reading process. POM_INCEPTION_YEAR=2016 POM_URL=https://github.com/nisrulz/qreader diff --git a/qreader/build.gradle b/qreader/build.gradle index 50e1c02..222157a 100644 --- a/qreader/build.gradle +++ b/qreader/build.gradle @@ -14,20 +14,4 @@ * limitations under the License. */ -plugins { - id 'com.android.library' - id 'kotlin-android' -} -// Apply common configs -apply from: "${rootDir}/configs/dependencies.gradle" -apply from: "${rootDir}/configs/android.gradle" apply from: "${rootDir}/configs/library.gradle" - -android { - compileSdk versions.compileSdk -} - -dependencies { - implementation androidXDeps.annotation - api vision -} From 33f8aec4368ccb9e6c6f8df696b43d6a2f49e073 Mon Sep 17 00:00:00 2001 From: Nishant Srivastava Date: Fri, 29 Oct 2021 02:42:11 +0200 Subject: [PATCH 5/5] fix version in license header --- configs/all_projects.gradle | 16 ++++++++++++++++ configs/android.gradle | 2 +- configs/dependencies.gradle | 2 +- configs/library.gradle | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/configs/all_projects.gradle b/configs/all_projects.gradle index 30638e6..52bb7be 100644 --- a/configs/all_projects.gradle +++ b/configs/all_projects.gradle @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2016 Nishant Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + allprojects { repositories { google() diff --git a/configs/android.gradle b/configs/android.gradle index f089892..fc9fdb6 100644 --- a/configs/android.gradle +++ b/configs/android.gradle @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Nishant Srivastava + * Copyright (C) 2016 Nishant Srivastava * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/configs/dependencies.gradle b/configs/dependencies.gradle index 5557636..f47f410 100644 --- a/configs/dependencies.gradle +++ b/configs/dependencies.gradle @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Nishant Srivastava + * Copyright (C) 2016 Nishant Srivastava * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/configs/library.gradle b/configs/library.gradle index a7701a2..6f54a76 100644 --- a/configs/library.gradle +++ b/configs/library.gradle @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Nishant Srivastava + * Copyright (C) 2016 Nishant Srivastava * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.