这是我第一次做动态特性模块。我在最小化gradle任务中遇到了问题。它写着ListenableFuturebase.jar和alt_acco.jar
下面是我的项目配置:
mobile.gradle
dynamicFeatures = [':alt_acco']
alt_acco.gradle。功能模块
apply plugin: 'com.android.dynamic-feature'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
tasks.lint.enabled = false
}
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
missingDimensionStrategy 'react-native-camera', 'general'
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
incremental true
}
buildTypes {
release {
}
releaseStaging {
matchingFallbacks = ['release']
}
debug {
}
}
productFlavors {
flavorDimensions "type"
standard {
dimension "type"
buildConfigField 'Boolean', 'Automation', 'false'
}
standardBasicOptimized {
dimension "type"
buildConfigField 'Boolean', 'Automation', 'false'
}
standard_charles {
dimension "type"
buildConfigField 'Boolean', 'Automation', 'false'
}
automation_charles {
dimension "type"
buildConfigField 'Boolean', 'Automation', 'true'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}
dependencies {
// Import the Firebase BoM (see: https://firebase.google.com/docs/android/learn-more#bom)
implementation platform('com.google.firebase:firebase-bom:28.2.1')
// Firestore (Java)
implementation 'com.google.firebase:firebase-firestore'
// Firestore (Kotlin)
implementation 'com.google.firebase:firebase-firestore-ktx'
// Google Play services
implementation project(path: ':mobile')
}
settings.gradle
include ':alt_acco'
我正在制作一个发布版本,我得到的错误如下:
Task :mobile:minifyStandardBasicOptimizedReleaseWithR8
/root/.gradle/caches/transforms-3/1169397e4788b932b8c86a71183af227/transformed/jetified-time4j-android-4.2-2018i/proguard.txt:1:1-27: R8: Ignoring option: -useuniqueclassmembernames
/opt/jenkins/workspace/APP-Android-Verify/mobile/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/base.jar: R8: Type com.google.common.util.concurrent.ListenableFuture is defined multiple times: /opt/jenkins/workspace/APP-Android-Verify/mobile/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/base.jar:com/google/common/util/concurrent/ListenableFuture.class, /opt/jenkins/workspace/APP-Android-Verify/alt_acco/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/feature-alt_acco.jar:com/google/common/util/concurrent/ListenableFuture.class
> Task :mobile:minifyStandardBasicOptimizedReleaseWithR8 FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':mobile:minifyStandardBasicOptimizedReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /opt/jenkins/workspace/APP-Android-Verify/mobile/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/base.jar:com/google/common/util/concurrent/ListenableFuture.class
非常感谢你的帮助。
嘿,我有同样的问题,因为我们有gradle缓存启用,我得到它的工作通过添加./gradlew bundleRelease --no-build-cache
,希望它有帮助。
这个错误说的是你的类com/google/common/util/concurrent/ListenableFuture
出现了两次,一次在你的基本模块,一次在你的:alt_acco
模块。
你的应用只需要依赖这个类一次。为了确保它在两种情况下(1)仅安装基本模块和(2)安装基本模块和:alt_acco
模块时都能工作,您应该从:alt_acco
模块中删除该类。
exclude
指令。它的工作方式是首先找到依赖于具有com/google/common/util/concurrent/ListenableFuture
类的库的依赖项。为此,使用Gradle并运行命令./gradlew alt_acco:dependencies
。至于其他选择,看看这个好答案。你应该得到一个依赖树,现在你应该找到有一个像com.google.common.util...
开头的组的行。您找到工件并排除它。
您可以通过在alt_acco
的build.gradle
文件的相关行中指定其组和模块来排除依赖工件:
implementation('direct-dependency-group:direct-dependency-module') {
exclude group: 'duplicate-dependency-group', module: 'duplicate-dependency-module'
}
直接依赖是你的alt_acco
模块中的一个,而重复依赖将是包含重复类com/google/common/util/concurrent/ListenableFuture
的那个。