![](/img/trans.png)
[英]Error:Unable to resolve dependency for ':app@debug/compileClasspath
[英]Switching Android module from library to application results in “Unable to resolve dependency for :app@debug/compileClasspath”/
我有一個Android應用程序,想作為模塊導入到我的項目中。 該模塊可以使用apply plugin: 'com.android.application'
同步和編譯,但是,我想在項目中使用該模塊中的某些類。 為此,似乎我需要根據該問題切換模塊的讀碼以讀取Apply apply plugin: 'com.android.library'
。 但是,將模塊從應用程序更改為庫會導致以下錯誤日志:
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文件。 這樣安全嗎? 另外,我要做的主要事情是能夠在應用程序活動中使用模塊中的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(Module: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文件。
現在轉到項目結構>添加模塊依賴性並添加模塊。
希望這可以幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.