这是我的构建。gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.jetbrains.dokka'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.me.daggersample"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "version"
productFlavors {
production {
dimension "version"
minSdkVersion 17
}
uiTest {
dimension "version"
minSdkVersion 18
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
}
}
// To resolve //Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
// https://stackoverflow.com/questions/48988778/cannot-inline-bytecode-built-with-jvm-target-1-8-into-bytecode-that-is-being-bui
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/javadoc"
}
configurations {
androidTestImplementation.exclude module: 'guava'
androidTestImplementation.exclude module: 'error_prone_annotations'
androidTestImplementation.exclude module: 'checker-compat-qual'
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-alpha04'
//Navigation
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-rc02'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-rc02'
testImplementation 'org.mockito:mockito-inline:2.7.13'
testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.5.0'
/*
testImplementation 'org.robolectric:robolectric:4.0.2'
testImplementation 'android.arch.core:core-testing:1.1.1'*/
androidTestImplementation 'org.mockito:mockito-android:2.19.0'
androidTestImplementation "org.robolectric:robolectric:4.2"
androidTestImplementation 'androidx.test:core:' + rootProject.coreVersion
androidTestImplementation 'androidx.test:core-ktx:' + rootProject.coreVersion
androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
androidTestImplementation 'androidx.test.ext:junit-ktx:' + rootProject.extJUnitVersion
androidTestImplementation 'androidx.test:runner:' + rootProject.runnerVersion
androidTestImplementation 'androidx.test.espresso:espresso-core:' + rootProject.espressoVersion
androidTestImplementation 'androidx.test.espresso:espresso-intents:' + rootProject.espressoVersion
testImplementation 'junit:junit:4.12'
// UiAutomator Testing
androidTestImplementation 'androidx.test.uiautomator:uiautomator:' + rootProject.uiautomatorVersion;
androidTestImplementation 'org.hamcrest:hamcrest-integration:1.3'
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.github.yongjhih.rx-mqtt:rx-mqtt-android:-SNAPSHOT'
// implementation 'com.afollestad:aesthetic:1.0.0-beta05'
implementation 'com.github.SherlockGougou:MagicIndicator:1.6.0'
implementation 'com.patrickpissurno:ripple-effect:1.3.1'
}
该应用程序的构建和运行都很好,但是:当我试图运行UI自动测试时,我得到了错误:
AGPBI: {"kind":"error","text":"Program type already present: org.apache.maven.profiles.ProfileManager","sources":[{}],"tool":"D8"}
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForProductionDebugAndroidTest'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Program type already present: org.apache.maven.profiles.ProfileManager
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
将Robolectric
依赖项更改为
//Roboelectric
testImplementation ("org.robolectric:robolectric:$versions.robolectric"){
exclude group: 'org.apache.maven'
}
问题内容: 我的android应用拒绝生成以下错误: 我的build.gradle依赖项 当我添加com.github.GrenderG:Prefs依赖项时,它可能开始发生 问题答案: 将此行添加到build.gradle文件。
问题内容: 我将Android Studio更新为3.1,更新后出现此错误: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:transformDexArchiveWithExternalLibsDexMergerForDebug’. Caused by: java.lang.RuntimeE
如何排除故障?
问题内容: 每当我尝试构建项目时添加时,Android Studio都会说: 这是我的gradle脚本: 我是这种类型的错误的新手,但我没有发现与此错误有关的任何一种。谢谢 问题答案: 我也整天都在努力解决这个问题。最终,我成功地编译并运行了该项目。 首先,摆脱这一点: 在gradle.properties文件中添加以下内容: 最后,同步项目,然后进行编译。 如果不起作用,请清理项目,然后重新生成
我正在重构一个应用程序来使用AndroidX。我一直在努力摆脱所有不支持它的库。我以为我已经删除了所有使用支持库的库,但看起来仍然有一些东西在导入它。我现在得到一个错误: AGPBI:{“kind”:“Error”,“text”:“程序类型已存在:Android.support.v4.os.resultreceiver$MyResultreceiver”,“sources”:[{}],“工具”:“