代码之家  ›  专栏  ›  技术社区  ›  Hassan

Android Studio gradle模块依赖项错误

  •  1
  • Hassan  · 技术社区  · 8 年前

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

    gradle error

    注意:我想要 shared 模块为应用程序类型,以便在其中放置一些共享布局资源

    共享生成。格拉德尔

    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。格拉德尔

    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')
     }
    

    项目构建。格拉德尔

    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()
    }
    }
    

    设置。格拉德尔

    include ':shared', ':admin'
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   Geethakrishna Juluri    8 年前

    CompileSDK版本和buildToolsVersion应为同一版本

    试着像这样改变

    compileSdkVersion 27
    buildToolsVersion '27.0.0'
    
        2
  •  0
  •   Hassan    8 年前

    我解决了它,有三种类型的android模块:

    • 应用程序模块: 包含 code , resources 而构建产生 .Apk 文件
    • Android库: 包含 密码 , 资源 而构建产生 .AAR 文件
    • Java库: 包含 密码 而构建产生 .JAR 文件

      应用程序模块可以依赖于另外两个,我转换了 shared 解决该问题的android库类型的模块。