From 5b2bd15a77b74fc66f7f6a05149a8aa52fa91905 Mon Sep 17 00:00:00 2001 From: Yongce Tu Date: Thu, 26 Mar 2020 00:05:08 +0800 Subject: [PATCH] Refactor the build configs to make the modules's source code can be included by other projects --- .gitignore | 69 +++++++++-- .idea/.name | 1 + .idea/codeStyles/Project.xml | 116 ++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/compiler.xml | 22 ++++ .idea/copyright/profiles_settings.xml | 3 + .idea/misc.xml | 100 +++++++++++++++ .idea/runConfigurations.xml | 12 ++ android_module_common.gradle | 8 +- android_project_common.gradle | 6 +- archLib/build.gradle | 13 +- .../me/ycdev/android/arch/ArchConstants.kt | 7 -- archLintRulesTestDemo/build.gradle | 1 + baseLib/build.gradle | 9 +- .../android/lib/common/utils/IntentUtils.kt | 9 ++ build.gradle | 13 +- build_common.gradle | 3 + jniLib/build.gradle | 7 +- jniLibDemo/build.gradle | 3 +- settings.gradle | 2 +- testLib/build.gradle | 7 +- uiLib/build.gradle | 10 +- .../commonui/activity/GridEntriesActivity.kt | 19 ++- 23 files changed, 385 insertions(+), 60 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 build_common.gradle diff --git a/.gitignore b/.gitignore index 170ebc0..37a2efa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ # Built application files *.apk +*.aar *.ap_ +*.aab -# Files for the Dalvik VM +# Files for the ART/Dalvik VM *.dex # Java class files @@ -11,15 +13,14 @@ # Generated files bin/ gen/ +out/ +# Uncomment the following line in case you need and you don't have the release build type files in your app +# release/ # Gradle files .gradle/ build/ -# Android Studio files -.idea/ -*.iml - # Local configuration file (sdk path, etc) local.properties @@ -29,11 +30,59 @@ proguard/ # Log Files *.log -# Mac OS -.DS_Store +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore -# JNI objects -obj/ -.externalNativeBuild/ +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild .cxx/ +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +# Mac OS +.DS_Store diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..f812c7d --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +AndroidLibProject \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9a8b7e5 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ca0bf9e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + Class structureJava + + + Code maturity issuesJava + + + Java + + + Java language level migration aidsJava + + + Javadoc issuesJava + + + Performance issuesJava + + + TestNGJava + + + Threading issuesJava + + + + + StringBufferToStringInConcatenation + + + + + + + + + + + + + + + 1.7 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/android_module_common.gradle b/android_module_common.gradle index c41d95f..057ec95 100644 --- a/android_module_common.gradle +++ b/android_module_common.gradle @@ -1,7 +1,7 @@ /* * File: 'android_module_common.gradle' * Location: https://raw.githubusercontent.com/yongce/AndroidLib/master/android_module_common.gradle - * Version: 2020.03.08 + * Version: 2020.03.26 * All android projects can copy and include this file. */ @@ -138,8 +138,10 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = "1.8" + pluginManager.withPlugin('kotlin-android') { + kotlinOptions { + jvmTarget = "1.8" + } } testOptions { diff --git a/android_project_common.gradle b/android_project_common.gradle index feb494c..e85987e 100644 --- a/android_project_common.gradle +++ b/android_project_common.gradle @@ -1,7 +1,7 @@ /* * File: 'android_project_common.gradle' * Location: https://raw.githubusercontent.com/yongce/AndroidLib/master/android_project_common.gradle - * Version: 2020.03.24 + * Version: 2020.03.26 * All android projects can copy and include this file. */ @@ -36,7 +36,7 @@ ext { 'compileSdk' : 29, // Android official support - 'kotlin' : "1.3.70", + 'kotlin' : "1.3.71", 'kotlinCoroutine' : "1.3.4", 'multidexLib' : "2.0.1", 'androidxCore' : "1.2.0", @@ -96,7 +96,7 @@ ext { 'rxandroid' : "2.1.1", // ycdev - 'androidLib' : "1.5.5", + 'androidLib' : "1.6.0", // others 'zxing' : "3.3.1", diff --git a/archLib/build.gradle b/archLib/build.gradle index 4820f34..1691cf1 100644 --- a/archLib/build.gradle +++ b/archLib/build.gradle @@ -2,8 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply from: "${androidModuleCommon}" - -project.archivesBaseName = 'common-arch' +apply from: '../build_common.gradle' android { defaultConfig { @@ -17,16 +16,8 @@ android { dependencies { lintChecks project(':archLintRules') lintPublish project(':archLintRules') - api project(':baseLib') + api deps.ycdev.androidBase implementation deps.kotlin.stdlib implementation deps.androidx.appcompat } - -project.ext { - moduleName = 'me.ycdev.android.common-arch' - moduleDesc = 'Common arch module in AndroidLib project' -} - -apply from: rootProject.file('bintray-install.gradle') -apply from: rootProject.file('bintray-upload.gradle') diff --git a/archLib/src/main/java/me/ycdev/android/arch/ArchConstants.kt b/archLib/src/main/java/me/ycdev/android/arch/ArchConstants.kt index 630b734..2ba7a3e 100644 --- a/archLib/src/main/java/me/ycdev/android/arch/ArchConstants.kt +++ b/archLib/src/main/java/me/ycdev/android/arch/ArchConstants.kt @@ -4,13 +4,6 @@ import android.widget.Toast import androidx.annotation.IntDef object ArchConstants { - const val INTENT_TYPE_ACTIVITY = 1 - const val INTENT_TYPE_BROADCAST = 2 - const val INTENT_TYPE_SERVICE = 3 - - @IntDef(INTENT_TYPE_ACTIVITY, INTENT_TYPE_BROADCAST, INTENT_TYPE_SERVICE) - @Retention(AnnotationRetention.SOURCE) - annotation class IntentType /* * Durations for toast diff --git a/archLintRulesTestDemo/build.gradle b/archLintRulesTestDemo/build.gradle index 8495dd2..bac6505 100644 --- a/archLintRulesTestDemo/build.gradle +++ b/archLintRulesTestDemo/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "${androidModuleCommon}" +apply from: '../build_common.gradle' android { defaultConfig { diff --git a/baseLib/build.gradle b/baseLib/build.gradle index 7f74a94..d9b835a 100644 --- a/baseLib/build.gradle +++ b/baseLib/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply from: "${androidModuleCommon}" +apply from: '../build_common.gradle' project.archivesBaseName = 'common-base' @@ -25,7 +26,7 @@ dependencies { implementation deps.timber // Dependencies for local unit tests - testImplementation project(':testLib') + testImplementation deps.ycdev.androidTest testImplementation deps.test.junit testImplementation deps.test.runner testImplementation deps.test.rules @@ -48,5 +49,7 @@ project.ext { moduleDesc = 'Common basic module in AndroidLib project' } -apply from: rootProject.file('bintray-install.gradle') -apply from: rootProject.file('bintray-upload.gradle') +if (bintrayUploadEnabled) { + apply from: rootProject.file('bintray-install.gradle') + apply from: rootProject.file('bintray-upload.gradle') +} diff --git a/baseLib/src/main/java/me/ycdev/android/lib/common/utils/IntentUtils.kt b/baseLib/src/main/java/me/ycdev/android/lib/common/utils/IntentUtils.kt index 6c47328..14f68b2 100644 --- a/baseLib/src/main/java/me/ycdev/android/lib/common/utils/IntentUtils.kt +++ b/baseLib/src/main/java/me/ycdev/android/lib/common/utils/IntentUtils.kt @@ -10,12 +10,21 @@ import android.content.pm.PackageManager import android.os.Build.VERSION import android.os.Build.VERSION_CODES import android.os.PowerManager +import androidx.annotation.IntDef import timber.log.Timber @Suppress("MemberVisibilityCanBePrivate") object IntentUtils { private const val TAG = "IntentUtils" + const val INTENT_TYPE_ACTIVITY = 1 + const val INTENT_TYPE_BROADCAST = 2 + const val INTENT_TYPE_SERVICE = 3 + + @IntDef(INTENT_TYPE_ACTIVITY, INTENT_TYPE_BROADCAST, INTENT_TYPE_SERVICE) + @Retention(AnnotationRetention.SOURCE) + annotation class IntentType + const val EXTRA_FOREGROUND_SERVICE = "extra.foreground_service" fun canStartActivity(cxt: Context, intent: Intent): Boolean { diff --git a/build.gradle b/build.gradle index 4047ae3..97f7c61 100644 --- a/build.gradle +++ b/build.gradle @@ -32,10 +32,9 @@ allprojects { } ext { - versions.minSdk = 21 versions.ndkVersion = "21.0.6113669" - // For bintray upload + bintrayUploadEnabled = true bintrayMaven = [ 'projectRepo': 'android', 'projectUrl': 'https://github.com/yongce/AndroidLib', @@ -43,11 +42,19 @@ ext { 'projectScmDevConnection': 'ssh://git@github.com/yongce/AndroidLib.git', 'projectInceptionYear': '2013', 'groupId': 'me.ycdev.android', - 'version': '1.5.5', + 'version': '1.6.0', 'developerId': 'yongce', 'developerName': 'Yongce Tu', 'developerEmail': 'yongce.tu@gmail.com', ] + + // Trick: other projects can redefine the mapping to include the modules directly + deps.ycdev = [ + 'androidBase': project(':baseLib'), + 'androidUi' : project(':uiLib'), + 'androidJni' : project(':jniLib'), + 'androidTest': project(':testLib'), + ] } spotless { diff --git a/build_common.gradle b/build_common.gradle new file mode 100644 index 0000000..dfbb7cf --- /dev/null +++ b/build_common.gradle @@ -0,0 +1,3 @@ +ext { + versions.minSdk = 21 +} diff --git a/jniLib/build.gradle b/jniLib/build.gradle index e25f2c9..4869e94 100644 --- a/jniLib/build.gradle +++ b/jniLib/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply from: "${androidModuleCommon}" +apply from: '../build_common.gradle' project.archivesBaseName = 'common-jni' @@ -46,5 +47,7 @@ project.ext { moduleDesc = 'Common jni module in AndroidLib project' } -apply from: rootProject.file('bintray-install.gradle') -apply from: rootProject.file('bintray-upload.gradle') +if (bintrayUploadEnabled) { + apply from: rootProject.file('bintray-install.gradle') + apply from: rootProject.file('bintray-upload.gradle') +} diff --git a/jniLibDemo/build.gradle b/jniLibDemo/build.gradle index 518661d..97270db 100644 --- a/jniLibDemo/build.gradle +++ b/jniLibDemo/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply from: "${androidModuleCommon}" +apply from: '../build_common.gradle' android { defaultConfig { @@ -29,7 +30,7 @@ android { } dependencies { - implementation project(':jniLib') + implementation deps.ycdev.androidJni implementation project(':archLib') implementation deps.kotlin.stdlib diff --git a/settings.gradle b/settings.gradle index a0a5175..61de367 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ -rootProject.name = 'AndroidLib' +rootProject.name = 'AndroidLibProject' include ':baseLib' diff --git a/testLib/build.gradle b/testLib/build.gradle index c35b50d..7826f57 100644 --- a/testLib/build.gradle +++ b/testLib/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply from: "${androidModuleCommon}" +apply from: '../build_common.gradle' project.archivesBaseName = 'common-test' @@ -39,5 +40,7 @@ project.ext { moduleDesc = 'Common test module in AndroidLib project' } -apply from: rootProject.file('bintray-install.gradle') -apply from: rootProject.file('bintray-upload.gradle') +if (bintrayUploadEnabled) { + apply from: rootProject.file('bintray-install.gradle') + apply from: rootProject.file('bintray-upload.gradle') +} diff --git a/uiLib/build.gradle b/uiLib/build.gradle index e4928d8..e6b0b09 100644 --- a/uiLib/build.gradle +++ b/uiLib/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply from: "${androidModuleCommon}" +apply from: '../build_common.gradle' project.archivesBaseName = 'common-ui' @@ -18,8 +19,7 @@ android { } dependencies { - api project(':archLib') - api project(':baseLib') + api deps.ycdev.androidBase implementation deps.kotlin.stdlib implementation deps.androidx.appcompat @@ -32,5 +32,7 @@ project.ext { moduleDesc = 'Common UI module in AndroidLib project' } -apply from: rootProject.file('bintray-install.gradle') -apply from: rootProject.file('bintray-upload.gradle') +if (bintrayUploadEnabled) { + apply from: rootProject.file('bintray-install.gradle') + apply from: rootProject.file('bintray-upload.gradle') +} diff --git a/uiLib/src/main/java/me/ycdev/android/lib/commonui/activity/GridEntriesActivity.kt b/uiLib/src/main/java/me/ycdev/android/lib/commonui/activity/GridEntriesActivity.kt index db3e9a8..2c9048e 100644 --- a/uiLib/src/main/java/me/ycdev/android/lib/commonui/activity/GridEntriesActivity.kt +++ b/uiLib/src/main/java/me/ycdev/android/lib/commonui/activity/GridEntriesActivity.kt @@ -11,21 +11,20 @@ import android.view.ViewGroup import android.widget.ProgressBar import android.widget.Toast import androidx.annotation.LayoutRes +import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView -import me.ycdev.android.arch.ArchConstants -import me.ycdev.android.arch.ArchConstants.IntentType -import me.ycdev.android.arch.activity.AppCompatBaseActivity -import me.ycdev.android.arch.wrapper.ToastHelper import me.ycdev.android.lib.common.utils.IntentUtils +import me.ycdev.android.lib.common.utils.IntentUtils.INTENT_TYPE_ACTIVITY +import me.ycdev.android.lib.common.utils.IntentUtils.INTENT_TYPE_BROADCAST import me.ycdev.android.lib.common.wrapper.BroadcastHelper import me.ycdev.android.lib.commonui.R import me.ycdev.android.lib.commonui.databinding.CommonuiGridEntriesItemBinding import me.ycdev.android.lib.commonui.recyclerview.MarginItemDecoration @Suppress("MemberVisibilityCanBePrivate", "unused") -abstract class GridEntriesActivity : AppCompatBaseActivity() { +abstract class GridEntriesActivity : AppCompatActivity() { protected lateinit var entriesAdapter: SystemEntriesAdapter protected lateinit var gridView: RecyclerView @@ -44,28 +43,28 @@ abstract class GridEntriesActivity : AppCompatBaseActivity() { ) open class IntentEntry( - @IntentType val type: Int = ArchConstants.INTENT_TYPE_ACTIVITY, + @IntentUtils.IntentType val type: Int = INTENT_TYPE_ACTIVITY, val intent: Intent, title: String, desc: String, val perm: String? = null ) : Entry(title, desc) { constructor(intent: Intent, title: String, desc: String) : - this(ArchConstants.INTENT_TYPE_ACTIVITY, intent, title, desc) + this(INTENT_TYPE_ACTIVITY, intent, title, desc) override val clickAction: ((Context) -> Unit)? = ::onItemClicked override val longClickAction: ((Context) -> Unit)? = ::onItemLongClicked protected open fun onItemClicked(context: Context) { - if (type == ArchConstants.INTENT_TYPE_ACTIVITY) { + if (type == INTENT_TYPE_ACTIVITY) { IntentUtils.startActivity(context, intent) - } else if (type == ArchConstants.INTENT_TYPE_BROADCAST) { + } else if (type == INTENT_TYPE_BROADCAST) { BroadcastHelper.sendToExternal(context, intent, perm) } } protected open fun onItemLongClicked(context: Context) { - ToastHelper.show(context, desc, Toast.LENGTH_LONG) + Toast.makeText(context, desc, Toast.LENGTH_LONG).show() } }