【问题标题】:Android Studio gradle modules dependency errorAndroid Studio gradle模块依赖错误
【发布时间】:2018-06-08 22:03:51
【问题描述】:

当我包含共享模块依赖项时,我有一些共享相同内容的应用程序模块 (Adapters,Layouts,etc..) 我收到以下错误

注意:我希望我的 shared 模块是应用程序类型,以便在其中放入一些共享布局资源

共享 build.gradle

apply plugin: 'com.android.application'

android  {
compileSdkVersion 27
buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.hassan.shared"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:27.0.2'
}

adminbuild.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.hassan.admin"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.0'
implementation project(':shared')
 }

项目 build.gradle

buildscript {
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.android.databinding:dataBinder:1.0-rc1'
    classpath 'com.google.gms:google-services:3.1.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()

 maven {
        url "https://maven.google.com"
    }
    google()
}
}

settings.gradle

include ':shared', ':admin'

【问题讨论】:

标签: android gradle module dependencies


【解决方案1】:

compileSdkVersion 和 buildToolsVersion 应该是相同的版本

尝试像这样改变

compileSdkVersion 27
buildToolsVersion '27.0.0'

【讨论】:

  • 谢谢我将我的build toolsplatform-tools 更新到了最新版本,但问题仍然存在不告诉你,但我试一试
【解决方案2】:

我解决了,android 模块分为三种:

  • 应用程序模块: 包含coderesources 并生成.Apk 文件
  • Android 库: 包含 coderesources 并生成 .AAR 文件
  • Java 库: 包含 code 并且构建生成 .JAR 文件

    应用程序模块可以依赖于其他两个,我将我的 shared 模块转换为解决它的 android 库类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    相关资源
    最近更新 更多