简体   繁体   中英

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. 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. 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. 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. I have also seen it suggested to delete the .gradle file altogether. 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. If there is a better way to go about doing this, let me know.

Here is the code for my .gradle files.

settings.gradle:

include ':app'
include ':OCRTest'

build.gradle(Project):

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

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):

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):

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

Sync Gradle files.

Replace settings.gradle with this line:

include ':app', ':OCRTest'

Sync Gradle files again.

Now goto Project Structure>Add Module dependency and add module.

Hope this helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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