Android Studio工具问题(逐步梳理中~)
Android Studio使用中配合Gradle构建工具,由于Gradle的版本之前差异很大,因此有是在修改project的文件过程中会遇到各种问题,这里记录了我在开发过程中逐渐梳理的遇到的问题。
Project结构:
Project
? | ---- app
? | ---- phase1
? | ---- base
- app module 是入口模块,目前是空壳。
- phase1 module是第一阶段测试完成的模块,包含业务功能,UI交互等。
- base module是基本公共组件,包含公共库的配置等。
找不到DataBindingMapperImpl
DataBinding 是在AS过程中,apt会产生一些中间类,但也需要一些依赖库的支持。这里遇到了一个无法找到DataBindingMapperImpl类的提示。
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.databinding.DataBinderMapperImpl" on path: DexPathList[[zip file "/data/app/进程名-iS9nPJeG1xdw4qsgYI0vmg==/base.apk"],nativeLibraryDirectories=[/data/app/进程名-iS9nPJeG1xdw4qsgYI0vmg==/lib/arm64, /system/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at androidx.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:32)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at com.sanren1024.android.app1.ui.activity.MainActivity.onCreate(MainActivity.kt:74)
at android.app.Activity.performCreate(Activity.java:7458)
at android.app.Activity.performCreate(Activity.java:7448)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3533)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3738)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2226)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7779)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:990)
...
当请配置中,databinding配置在phase1模块的build.gradle文件中。开始运行后,遇到了上述配置。
phase1的build.gradle基本配置。**
android {
compileSdk 30
buildToolsVersion '30.0.3'
defaultConfig {
minSdk 26
targetSdk 30
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildFeatures {
dataBinding = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
}
dependencies {
kapt "androidx.room:room-compiler:2.3.0"
api project(':rxbase')
}
base的build.gradle依赖配置。**
dependencies {
api 'androidx.core:core-ktx:1.5.0'
api 'androidx.appcompat:appcompat:1.3.0'
api 'com.google.android.material:material:1.4.0'
api 'androidx.constraintlayout:constraintlayout:2.0.4'
api 'androidx.legacy:legacy-support-v4:1.0.0'
api "androidx.room:room-ktx:2.3.0"
api "androidx.room:room-runtime:2.3.0"
api 'org.slf4j:slf4j-api:1.7.25'
api 'com.github.tony19:logback-android:2.0.0'
api 'androidx.work:work-runtime-ktx:2.5.0'
api "androidx.multidex:multidex:2.0.1"
api "androidx.preference:preference-ktx:1.1.0"
api "androidx.preference:preference:1.1.0"
}
解决:
要在module中使用databinding,需要从app module到library module一条完整的以来路径上都配置上databinding=true 。
图形依赖说明参照stackoverflow databinding-not-working-in-module说明
|