android - 无法在 Android Studio 3 中将外部项目作为模块导入

标签 android gradle android-gradle-plugin android-studio-3.1

我已经在商店发布了一个应用程序,在升级到 Android Studio 3(现在是 3.1)并强制更新 gradle 之后,我无法将我的外部项目作为模块导入。

我试过删除所有模块并一一添加,删除缓存,更改 gradle 版本和 compileSdkVersion 但它不起作用。

当我尝试同步 gradle 时,我收到一些这样的消息:

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



这是在我的 settings.gradle 中,以使外部项目可用:
include ':app'

include ':ShareLib'
project(':ShareLib').projectDir = new File('..//ShareLib//')

这是我的 build.gradle
buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

repositories {
    jcenter()
    mavenCentral()
    mavenLocal()
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
    maven { url 'https://maven.fabric.io/public' }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
def AAVersion = '4.4.0'

android {
    compileSdkVersion 26
    buildToolsVersion "27.0.3"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 3
        versionName "1.0.0.0"

        applicationId "com.xxx.app"

        // Enabling multidex support.
        multiDexEnabled true

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["resourcePackageName": android.defaultConfig.applicationId]
            }
        }

    }

    signingConfigs {
        releaseSigning {
        ///
        }
    }

    buildTypes {

        debug {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
        }

        release {
            // proguard
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            shrinkResources false

            zipAlignEnabled true

            signingConfig signingConfigs.releaseSigning
        }
    }

    flavorDimensions "tier"

    productFlavors {

        dev {
            buildConfigField "String", "SERVICE_URL_BASE", "\"dev.xxx.com/xxx-rest\""
            applicationId "development.xxx.app"
        }

        coll {
            buildConfigField "String", "SERVICE_URL_BASE", "\"dev.xxx.com/xxx-rest\""
            applicationId "test.xxx.app"
        }

        prod {
            buildConfigField "String", "SERVICE_URL_BASE", "\"www.xxx.com/xxx-rest\""
            applicationId "com.xxx.app"
        }

    }


    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation project(path: ':shareLib', configuration: 'default')
//    implementation project(path: ':shareLib', configuration: 'default') {
//        exclude module: 'jsr305'
//    }
    //    compile fileTree(dir: 'libs', include: ['*.jar'])

    testImplementation 'junit:junit:4.12'
    implementation 'com.squareup:otto:1.3.8'
    implementation 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    implementation "org.androidannotations:androidannotations-api:$AAVersion"
    annotationProcessor "org.androidannotations:rest-spring:$AAVersion"
    implementation "org.androidannotations:rest-spring-api:$AAVersion"
    annotationProcessor "org.androidannotations:otto:$AAVersion"
    implementation "org.androidannotations:otto:$AAVersion"

    implementation 'com.github.bumptech.glide:glide:3.7.0'

    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'

    // support AA on Android < 5
//    compile 'com.android.support:multidex:1.0.1'

    implementation 'com.github.markomilos:paginate:0.5.1'

    // mpandroid
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'

    // crashlytics fabric
    implementation('com.crashlytics.sdk.android:crashlytics:2.6.1@aar') {
        transitive = true
    }

    // recaptcha
    implementation ('android.lib.recaptcha:reCAPTCHA:2.0.0') {
        exclude group: 'com.android.support'

    }

    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'

}

最佳答案

我已经一一解决了打开模块项目并为每个项目执行此操作:

  • 项目结构 -> 项目 -> Gradle 版本 = 4.7
  • 设置 -> 构建、执行、部署 -> 编译器 -> 取消选中“按需配置”
  • 一旦您可以在 build/outputs/aar
  • 中看到您的 .aar 文件,就重新构建项目

    然后对主项目模块重复这些步骤

    关于android - 无法在 Android Studio 3 中将外部项目作为模块导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50412550/

    相关文章:

    java - 如何格式化日期对象的输出(不是字符串)?

    android - fragment 相互重叠显示

    导致内核崩溃的 Java 8 gradle 脚本

    Gradle:任务不会根据它使用的配置执行另一个任务

    安卓工作室错误 : Configuration with name 'default' not found

    android - ':app:ndkBuild' 执行失败。进程 'command ndk-build.cmd' 以非零退出值 2 完成

    java - Google AppEngine - 如何为 Google AppEngine 设置默认字符集/文件编码(到 UTF-8)

    android - JUnit Launcher 测试...getActivity 未返回

    java - 从 Gradle 运行单个 cucumber-jvm .feature 文件

    android - 如何为发布/调试版本提供不同的 gradle.properties 文件?