Modify: 组件化基本模块实现

This commit is contained in:
Quyunshuo
2020-08-27 16:17:26 +08:00
parent 05e8604eb3
commit 2d04aa7824
37 changed files with 349 additions and 70 deletions

1
Lib_Base/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

72
Lib_Base/build.gradle Normal file
View File

@ -0,0 +1,72 @@
import com.quyunshuo.androidbaseframemvvm.build.*
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
compileSdkVersion BuildConfig.compileSdkVersion
buildToolsVersion BuildConfig.buildToolsVersion
defaultConfig {
minSdkVersion BuildConfig.minSdkVersion
targetSdkVersion BuildConfig.targetSdkVersion
versionCode BuildConfig.versionCode
versionName BuildConfig.versionName
testInstrumentationRunner AndroidX.AndroidJUnitRunner
consumerProguardFiles "consumer-rules.pro"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
kapt {
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
api AndroidX.CoreKtx
api AndroidX.AppCompat
api AndroidX.ConstraintLayout
api AndroidX.ActivityKtx
api AndroidX.FragmentKtx
api Kotlin.Kotlin
api Kotlin.CoroutinesCore
api Kotlin.CoroutinesAndroid
api JetPack.LifecycleRuntimeKtx
api JetPack.LifecycleViewModel
api JetPack.LifecycleViewModelKtx
api JetPack.HiltLifecycleViewModel
api JetPack.HiltDaggerAndroid
api GitHub.OkHttp
api GitHub.OkHttpInterceptorLogging
api GitHub.Retrofit
api GitHub.RetrofitConverterGson
api GitHub.Gson
api GitHub.MMKV
api GitHub.AutoSize
api GitHub.Glide
api GitHub.ARoute
api GitHub.RecyclerViewAdapter
kapt JetPack.HiltDaggerCompiler
kapt JetPack.Hilt
kapt GitHub.GlideCompiler
kapt GitHub.ARouteCompiler
}

View File

21
Lib_Base/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.quyunshuo.base">
/
</manifest>

View File

@ -0,0 +1,12 @@
package com.quyunshuo.base
import android.app.Application
/**
* @Author: QuYunShuo
* @Time: 2020/8/27
* @Class: BaseApplication
* @Remark: 自定义Application的基类
*/
open class BaseApplication : Application() {
}

View File

@ -1,6 +1,7 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

1
Lib_Main/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

5
Lib_Main/build.gradle Normal file
View File

@ -0,0 +1,5 @@
apply from: '../moduleBase.gradle'
android {
resourcePrefix "main_"
}

View File

21
Lib_Main/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -1,4 +1,4 @@
package com.quyunshuo.androidbaseframemvvm
package com.quyunshuo.main
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
@ -19,6 +19,6 @@ class ExampleInstrumentedTest {
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.quyunshuo.androidbaseframemvvm", appContext.packageName)
assertEquals("com.quyunshuo.main.test", appContext.packageName)
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.quyunshuo.main">
<application>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -1,11 +1,12 @@
package com.quyunshuo.androidbaseframemvvm
package com.quyunshuo.main
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.quyunshuo.main">
<application
android:name="com.quyunshuo.base.BaseApplication"
android:allowBackup="true"
android:label="@string/main_app_name"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -6,13 +6,4 @@
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,3 @@
<resources>
<string name="main_app_name">Lib_Main</string>
</resources>

View File

@ -1,4 +1,4 @@
package com.quyunshuo.androidbaseframemvvm
package com.quyunshuo.main
import org.junit.Test

View File

@ -1 +1,5 @@
# Android项目框架(组件化 + Kotlin + MVVM + Jetpack )
note: 1. 组件间资源命名冲突问题
2. 组件间不同模式下的清单文件及其他
3. 测试打包脚本
4. Application

View File

@ -3,7 +3,6 @@ import com.quyunshuo.androidbaseframemvvm.build.*
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion BuildConfig.compileSdkVersion
@ -16,59 +15,63 @@ android {
versionCode BuildConfig.versionCode
versionName BuildConfig.versionName
testInstrumentationRunner AndroidX.AndroidJUnitRunner
}
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
// signingConfigs {
// releaseConfig {
// storeFile file('')
// storePassword ""
// keyAlias ""
// keyPassword ""
// }
// }
buildTypes {
release {
// signingConfig signingConfigs.releaseConfig
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (outputFileName != null
&& outputFileName.endsWith('.apk')
&& 'release' == variant.buildType.name) {
outputFileName = "${BuildConfig.applicationId}_${defaultConfig.versionCode}(${defaultConfig.versionName}).apk"
}
}
}
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (outputFileName != null
&& outputFileName.endsWith('.apk')
&& 'debug' == variant.buildType.name) {
outputFileName = "${BuildConfig.applicationId}_${defaultConfig.versionCode}(${defaultConfig.versionName}).apk"
}
}
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
viewBinding {
enabled = true
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
testImplementation Android.Junit
implementation AndroidX.CoreKtx
implementation AndroidX.AppCompat
implementation AndroidX.ConstraintLayout
implementation AndroidX.ActivityKtx
implementation AndroidX.FragmentKtx
androidTestImplementation AndroidX.TestExtJunit
androidTestImplementation AndroidX.TestEspresso
implementation Kotlin.Kotlin
implementation Kotlin.CoroutinesCore
implementation Kotlin.CoroutinesAndroid
implementation JetPack.LifecycleRuntimeKtx
implementation JetPack.LifecycleViewModel
implementation JetPack.LifecycleViewModelKtx
implementation JetPack.HiltLifecycleViewModel
implementation JetPack.HiltDaggerAndroid
kapt JetPack.HiltDaggerCompiler
kapt JetPack.Hilt
implementation GitHub.OkHttp
implementation GitHub.OkHttpInterceptorLogging
implementation GitHub.Retrofit
implementation GitHub.RetrofitConverterGson
implementation GitHub.Gson
implementation GitHub.MMKV
implementation GitHub.AutoSize
implementation GitHub.Glide
kapt GitHub.GlideCompiler
implementation GitHub.ARoute
kapt GitHub.ARouteCompiler
implementation GitHub.RecyclerViewAdapter
implementation AndroidX.MultiDex
if (!BuildConfig.isAppMode) {
implementation project(path: ':Lib_Main')
} else {
implementation project(path: ':Lib_Base')
}
}

View File

@ -3,19 +3,12 @@
package="com.quyunshuo.androidbaseframemvvm">
<application
android:name=".AppApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
android:theme="@style/AppTheme" />
</manifest>

View File

@ -0,0 +1,18 @@
package com.quyunshuo.androidbaseframemvvm
import androidx.multidex.MultiDex
import com.quyunshuo.base.BaseApplication
/**
* @Author: QuYunShuo
* @Time: 2020/8/27
* @Class: AppApplication
* @Remark: 壳App的Application 负责需要写在App包下的初始化逻辑
*/
class AppApplication : BaseApplication() {
override fun onCreate() {
super.onCreate()
MultiDex.install(this)
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -10,6 +10,7 @@ buildscript {
dependencies {
classpath ProjectPluginManager.AndroidToolsPlugin
classpath ProjectPluginManager.KotlinPlugin
classpath ProjectPluginManager.DaggerHiltPlugin
}
}

View File

@ -11,4 +11,5 @@ object BuildConfig {
const val targetSdkVersion = 30
const val versionCode = 1
const val versionName = "1.0"
const val isAppMode = false
}

View File

@ -12,11 +12,15 @@ object Version {
const val TestEspresso = "3.3.0"
const val ActivityKtx = "1.1.0"
const val FragmentKtx = "1.2.5"
const val MultiDex = "2.0.1"
// Android---------------------------------------------------------------
const val Junit = "4.13"
// Kotlin----------------------------------------------------------------
const val Kotlin = "1.4.0"
const val Coroutines = "1.3.7" // 协程
// JetPack---------------------------------------------------------------
const val LifecycleViewModel = "2.2.0"
const val LifecycleRuntimeKtx = "2.2.0"
@ -24,6 +28,7 @@ object Version {
const val Hilt = "1.0.0-alpha02" // Hilt 依赖注入
const val HiltLifecycleViewModel = "1.0.0-alpha02"
const val HiltDagger = "2.28-alpha"
// GitHub----------------------------------------------------------------
const val OkHttp = "3.14.9" // OkHttp
const val OkHttpInterceptorLogging = "3.12.0" // OkHttp 请求Log拦截器
@ -48,6 +53,7 @@ object AndroidX {
const val TestEspresso = "androidx.test.espresso:espresso-core:${Version.TestEspresso}"
const val ActivityKtx = "androidx.activity:activity-ktx:${Version.ActivityKtx}"
const val FragmentKtx = "androidx.fragment:fragment-ktx:${Version.FragmentKtx}"
const val MultiDex = "androidx.multidex:multidex:${Version.MultiDex}"
}
object Android {

View File

@ -6,4 +6,5 @@ package com.quyunshuo.androidbaseframemvvm.build
object ProjectPluginManager {
const val AndroidToolsPlugin = "com.android.tools.build:gradle:4.0.1"
const val KotlinPlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0"
const val DaggerHiltPlugin = "com.google.dagger:hilt-android-gradle-plugin:2.28.1-alpha"
}

82
moduleBase.gradle Normal file
View File

@ -0,0 +1,82 @@
import com.quyunshuo.androidbaseframemvvm.build.*
if (BuildConfig.isAppMode) {
apply plugin: 'com.android.application'
} else {
apply plugin: 'com.android.library'
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
compileSdkVersion BuildConfig.compileSdkVersion
buildToolsVersion BuildConfig.buildToolsVersion
defaultConfig {
minSdkVersion BuildConfig.minSdkVersion
targetSdkVersion BuildConfig.targetSdkVersion
versionCode BuildConfig.versionCode
versionName BuildConfig.versionName
testInstrumentationRunner AndroidX.AndroidJUnitRunner
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
buildFeatures {
viewBinding = true
}
//根据不同的模式加载不同的AndroidManifest文件
sourceSets {
main {
if (BuildConfig.isAppMode) {
manifest.srcFile 'src/main/java/debug/AndroidManifest.xml'
} else {
manifest.srcFile 'src/main/AndroidManifest.xml'
java {
//排除debug文件夹下的所有文件
exclude 'debug/**'
}
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
kapt {
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(path: ':Lib_Base')
testImplementation Android.Junit
androidTestImplementation AndroidX.TestExtJunit
androidTestImplementation AndroidX.TestEspresso
api JetPack.HiltDaggerAndroid
kapt JetPack.HiltDaggerCompiler
kapt JetPack.Hilt
}

View File

@ -1,2 +1,4 @@
include ':Lib_Main'
include ':Lib_Base'
include ':app'
rootProject.name = "AndroidBaseFrameMVVM"