繁体   English   中英

将Android模块从库切换到应用程序会导致“无法解析: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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM