gpt4 book ai didi

java - 将 Android 模块从库切换到应用程序会导致 "Unable to resolve dependency for :app@debug/compileClasspath"/

转载 作者:行者123 更新时间:2023-12-03 05:42:45 26 4
gpt4 key购买 nike

我有一个要作为模块导入到我的项目中的 android 应用程序。该模块与 apply plugin: 'com.android.application' 同步和编译良好但是,我想在我的项目中使用模块中的一些类。为此,我似乎需要将模块的 gradle 切换为读取 apply plugin: 'com.android.library'根据 this question.但是,将模块从应用程序更改为库会导致以下错误日志:

Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform file 'OCRTest-release.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Failed to transform file 'OCRTest-release.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform

...

Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Failed to transform file 'OCRTest-release.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform

到目前为止,我已经尝试过使缓存无效并重新启动 Android Studio,因为这是一个常见的建议。我还看到它建议完全删除 .gradle 文件。这样做安全吗?此外,我想做的主要事情是能够在我的应用程序 Activity 中使用模块中的 Java 类。如果有更好的方法可以做到这一点,请告诉我。

这是我的 .gradle 文件的代码。

settings.gradle:
include ':app'
include ':OCRTest'

build.gradle(项目):
buildscript {

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// 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
}

build.gradle(模块:OCRTest):这是包含我想在我的应用程序中使用的类的模块
apply plugin: 'com.android.library'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
minSdkVersion 15
targetSdkVersion 27
}

buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}

dependencies {
implementation 'com.rmtheis:tess-two:9.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
}

build.gradle(模块:应用程序):
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
applicationId "org.noblis.thirdeye"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ['debug']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.rmtheis:tess-two:9.0.0'
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'
implementation project(path: ':OCRTest', configuration: 'default')
}

最佳答案

从 build.gradle(Module:app) 中删除以下行:

implementation project(path: ':OCRTest', configuration: 'default')

同步 Gradle 文件。

将 settings.gradle 替换为以下行:
include ':app', ':OCRTest'

再次同步 Gradle 文件。

现在转到项目结构>添加模块依赖项并添加模块。

希望这可以帮助 :)

关于java - 将 Android 模块从库切换到应用程序会导致 "Unable to resolve dependency for :app@debug/compileClasspath"/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51756259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com