Gradle迁移3.1.4-> 3.5.1; :app模块无法编译; ClassNotFoundException:在路径:DexPathList上找不到类
我有两个应用程序在尝试将项目 target
API从27更新到29时遇到相同的问题。为此,我首先需要在以下位置更新Gradle插件至少为 3.2。+
。
I have two applications where I face the same issue while trying to update project target
API from 27 to 29. To do this, first I need to update Gradle plugin at least to 3.2.+
.
项目正在使用 3.1.4
进行良好的构建,但是一旦我将Gradle插件升级为: classpath'com.android.tools.build:gradle:3.5.1
distributionUrl = https\://services.gradle .org / distributions / gradle-5.4.1-all.zip
( 3.2.1
和更高版本的错误相同)
Project is building fine with 3.1.4
, but as soon as I rise Gradle plugin to:
classpath 'com.android.tools.build:gradle:3.5.1
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
(Same error with 3.2.1
and higher)
我看到下一个运行时异常:
I see next RunTime exception:
Process: com.my.app, PID: 29804
java.lang.RuntimeException: Unable to instantiate application com.my.app: java.lang.ClassNotFoundException: Didn't find class "com.my.app" on path: DexPathList[[zip file "/data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/lib/x86, /data/app/com.my.app-Y6_GNyscecqK5BtUnp_kjQ==/base.apk!/lib/x86, /system/lib]]
:app 模块源代码根本无法编译的问题
(我可以创建手动编译错误,并且
A problem that :app module source code is not compiled at all (I can create manual compilation error and run will be still successful)
在两个应用程序中都相同。
我很累:
The same in both application. What I tired:
- 我检查了APK中生成的DEX文件,源代码不存在;
- 我用
3.5.1
插件创建一个新项目-很好; - 尝试删除
gradle
和.idea
文件夹; - 尝试到 clean 和
使缓存无效
- 将项目迁移到
AndroidX
; - 添加了
multiDexEnabled true
-以前一直没有它就可以工作; - 复制到新项目的依赖项-工作正常;
- 添加到: gradle.properties
android.useAndroidX = true android.enableJetifier = true
- I checked generated DEX files in the APK, source code is not there;
- I create a new project with
3.5.1
plugin - it works fine; - Tried to delete
gradle
and.idea
folders; - Tried to to
clean
andinvalidate cache
- Migrated project to
AndroidX
; - Added
multiDexEnabled true
- it was working without it before, anyway; - Copied dependencies to a new Project - works fine;
- Added: to gradle.properties
android.useAndroidX=true android.enableJetifier=true
我的构建文件:
TOP级别
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:6.0.0"
classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.31.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用程序:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.my.app"
minSdkVersion 21
targetSdkVersion 29
versionCode 2
versionName "1.01"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
ext.anko_version='0.10.5'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.facebook.fresco:fresco:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.0'
implementation "org.jetbrains.anko:anko-sdk21:$anko_version"
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
implementation "org.jetbrains.anko:anko-constraint-layout:$anko_version"
implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"
implementation "org.jetbrains.anko:anko-cardview-v7:$anko_version"
implementation 'com.r0adkll:slidableactivity:2.0.6'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
kapt "io.realm:realm-annotations-processor:5.9.0"
}
apply plugin: 'com.google.gms.google-services'
注意:另一个具有不同依赖关系的项目仍然面临相同的问题
Note: another project has different set of dependencies still face the same issue
在迁移到较新的Gradle并在旧版本上正常工作时,为什么未将源代码添加到APK?
Why source code is not added to APK after migration to newer Gradle while working fine on the old one?
更新1
我将项目更新到Gradle 3.2 + $ c后,问题立即出现$ c>
更新2
Build文件夹不包含类文件夹和类文件
Update 2 Build folder doesn't contain class folder and class files
更新3
来自:app 模块的源代码即使在 settings.gradle 文件;我可以在任何.java文件中创建构建错误,并且 run 将成功执行
Update 3 Source code from :app module doesn't compile even tho it is in the settings.gradle file; I can create build error in any .java file and run will be executed successfully
我发现了一个问题:
我的一个软件包名称为vas cvs
-似乎是在Gradle 3.2之后。它是保留字。
I found an issue:
One of my packages name vas cvs
- seems it is after Gradle 3.2.+ it is reserved word.