[英]Switching Android module from library to application results in “Unable to resolve dependency for :app@debug/compileClasspath”/
I have an android app I want to import to my project as a module. 我有一个Android应用程序,想作为模块导入到我的项目中。 The module syncs and compiles fine with
apply plugin: 'com.android.application'
However, there are classes from the module that I want to use in my project. 该模块可以使用
apply plugin: 'com.android.application'
同步和编译,但是,我想在项目中使用该模块中的某些类。 To do this, it seems like I need to switch the gradle for the module to read apply plugin: 'com.android.library'
as per this question. 为此,似乎我需要根据该问题切换模块的读码以读取Apply
apply plugin: 'com.android.library'
。 However, changing the module from an application to a library results in the following error log: 但是,将模块从应用程序更改为库会导致以下错误日志:
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
So far I have tried invalidating caches and restarting Android Studio, as that was a common suggestion. 到目前为止,我已经尝试过使缓存无效并重新启动Android Studio,因为这是一个常见的建议。 I have also seen it suggested to delete the .gradle file altogether.
我也看到它建议完全删除.gradle文件。 Is that safe to do?
这样安全吗? Also, the main thing I want to do is be able to use Java classes from the module in my app's activities.
另外,我要做的主要事情是能够在应用程序活动中使用模块中的Java类。 If there is a better way to go about doing this, let me know.
如果有更好的方法可以进行此操作,请告诉我。
Here is the code for my .gradle files. 这是我的.gradle文件的代码。
settings.gradle: settings.gradle:
include ':app'
include ':OCRTest'
build.gradle(Project): 的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): This is the module that contains classes I want to use in my app 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(Module: app): 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')
}
Remove the following line from build.gradle(Module:app): 从build.gradle(Module:app)中删除以下行:
implementation project(path: ':OCRTest', configuration: 'default')
Sync Gradle files. 同步Gradle文件。
Replace settings.gradle with this line: 用以下行替换settings.gradle:
include ':app', ':OCRTest'
Sync Gradle files again. 再次同步Gradle文件。
Now goto Project Structure>Add Module dependency and add module. 现在转到项目结构>添加模块依赖性并添加模块。
Hope this helps :) 希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.