我有两个应用程序在尝试将项目target
API从27更新到29时遇到相同的问题。为此,首先我需要至少将Gradle插件更新为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
及更高版本相同的错误)
我看到下一个运行时异常:
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 模块源代码根本未编译的问题 (我可以创建手动编译错误,并且 run 仍然会成功)
在两个应用程序中相同。 我累了:
3.5.1
插件创建了一个新项目-效果很好; gradle
和.idea
文件夹; clean
和invalidate cache
AndroidX
; multiDexEnabled true
-无论如何之前都没有它; 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'
注意:另一个具有不同依赖关系的项目仍然面临相同的问题
为什么在迁移到较新的Gradle时仍能在旧版本上正常工作,但未将源代码添加到APK?
更新1
我将项目更新到Gradle 3.2+
更新2 Build文件夹不包含类文件夹和类文件
更新3 :app 模块的源代码即使在 settings.gradle 文件中也无法编译;我可以在任何.java文件中创建构建错误,并且 run 将成功执行
答案 0 :(得分:0)
我发现了一个问题:
我的一个软件包名称为vas cvs
-似乎是在Gradle 3.2。+之后的,它是保留字。