簡體   English   中英

在android studio中使用具有不同sdk版本的多個庫

[英]Using multiple library with different sdk version in android studio

有幾個問題,但還沒有相關的答案。 在我的android studio項目中,我使用了幾個不同版本的庫。 現在我面臨錯誤來運行項目。 我有一些庫有兩個不同的SDK版本。 一個是sdk = 25.3.1,另一個是sdk = 28.0.0這是我不同的build.gradle文件。

我的項目build.gradle文件

buildscript {
repositories {
    google()
    jcenter()
}
dependencies {

    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.google.gms:google-services:3.2.0'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
  }
}

allprojects {
repositories {
    google()
    maven { url 'http://raw.github.com/saki4510t/libcommon/master/repository/' }
    jcenter()
  }
}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
supportLibraryVersion = '28.0.0'  // variable that can be referenced to keep support libs consistent
supportLibVersion = '25.3.1'
commonLibVersion= '1.5.20'
//versionBuildTool = '26.0.2'
//versionCompiler = 25
//versionTarget = 22
//versionNameString = '1.0.0'
javaSourceCompatibility = JavaVersion.VERSION_1_7
javaTargetCompatibility = JavaVersion.VERSION_1_7
}

app:build.gradle文件

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId "com.jiangdg.usbcamera"
    minSdkVersion 19
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile project(':libusbcamera')
compile project(':libmlkit')
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.android.support:design:25.3.1'
}

我的庫build.gradle文件

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.jiangdongguo'

android {
          compileSdkVersion 25
          buildToolsVersion '26.0.2'

          defaultConfig {
                          minSdkVersion 19
                          targetSdkVersion 22
                          versionCode 1
                          versionName "1.0"

                          testInstrumentationRunner 
                          "android.support.test.runner.AndroidJUnitRunner"
        }
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile("com.serenegiant:common:${commonLibVersion}") {
    exclude module: 'support-v4'
  }
}

另一個庫build.gradle

apply plugin: 'com.android.library'

  android {
           compileSdkVersion 28
          defaultConfig {

    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
aaptOptions {
    noCompress "tflite"
}
}

   dependencies {
                 implementation fileTree(dir: 'libs', include: ['*.jar'])
                 implementation 'com.android.support:appcompat-v7:28.0.0'
                 implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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 'com.google.firebase:firebase-ml-vision:18.0.1'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
implementation 'co`apply plugin: 'com.google.gms.google-services'

  }

發生以下錯誤..

Android依賴項'com.android.support:appcompat-v7'對於編譯(25.3.1)和運行時(28.0.0)類路徑具有不同的版本>。 您應該手動>通過DependencyResolution設置相同的版本

您必須在build.gradle文件中為所有項目設置配置

subprojects {
afterEvaluate {
    project -> if (project.hasProperty("android")) {
        android {
            compileSdkVersion 28
            buildToolsVersion '28.0.0'
        }
    }
}

}

然后在你的應用程序build.gradle文件替換所有其他lib的配置

 configurations.all {
    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support') {
            details.useVersion "28.0.0"
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM