我尝试将android项目迁移到Android Studio 3.2.1。在此项目中,我使用Gradle 4.6。
我的android应用具有主应用和2个模块。
这是我的project / build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的app / build.gradle:
应用插件:“ com.android.application”
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myproject"
minSdkVersion 23
targetSdkVersion 28
versionCode 421
versionName "2.1.421"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
// must be version 4.5.2
def AAVersion = '4.5.2'
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
annotationProcessor "org.androidannotations:ormlite:$AAVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'org.apache.commons:commons-lang3:3.8.1'
implementation 'org.apache.httpcomponents:httpclient:4.5.6'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.j256.ormlite:ormlite-android:5.1'
implementation 'commons-io:commons-io:2.6'
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation "org.androidannotations:ormlite-api:$AAVersion"
implementation project(':module1')
implementation project(':module2')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
但是我得到了错误:
:app:transformClassesWithDexBuilderForDebug UP-TO-DATE
AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
:app:buildInfoGeneratorDebug
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
\My Project\android\FM\app\build\intermediates\transforms\dexBuilder\debug\0.jar,
\My Project\android\FM\app\build\intermediates\transforms\dexBuilder\debug\1.jar,
\My Project\android\FM\app\build\intermediates\transforms\dexBuilder\debug\2.jar,
\My Project\android\FM\app\build\intermediates\transforms\dexBuilder\debug\3.jar,
\My Project\android\FM\app\build\intermediates\transforms\dexBuilder\debug\4.jar, D:\dev\mobile\Factura
Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.