【问题标题】:Error creating new Android project with Android Studio使用 Android Studio 创建新的 Android 项目时出错
【发布时间】:2017-08-16 11:20:19
【问题描述】:

我刚刚使用 Android Studio 创建了一个新项目 Android,并且我选择了最低 SDK 9 (Gingerbread) 和活动 @987654321 @,一旦选择并创建了项目,我会收到以下错误:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 9 cannot be smaller than version 14 declared in library [com.android.support:design:26.0.0-alpha1] C:\xxx\xxx\.android\build-cache\bd439271136a9bc6f4bc228104359605401bab70\output\AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="android.support.design" to force usage

而且我没有触及或修改任何创建 Android Studio 本身的东西,我已经用最新版本更新了 SDK。

有什么建议吗?

Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "xx.xx.xx.seguros"
        minSdkVersion 9
        targetSdkVersion 26
        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:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    里面发生了什么。该库支持使用最低 SDK 版本 14 进行设计。因此,如果您的应用 minimumSdk 版本低于该版本,则无法使用此库。

    您应该使用com.android.support:design:25.+ 来支持 minSdkVersion 9。

    如果您使用com.android.support:design:26.0.0-alpha1。您必须使用 minSdkVersion 14

    像这样更新你的 gradle

    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "xx.xx.xx.seguros"
        minSdkVersion 14      // Update it to 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    

    希望对你有帮助:)

    【讨论】:

    • 感谢您的回答!如果我想将 sdk min 保持在 9?
    • 您应该使用较旧的设计库 25.0.0 可能可行。但不确定。
    • 旧版本 25 可以工作,使用它我可以维护 min sdk 9
    • 如您在评论中所说,输入您的答案,将 min sdk 保留为 9,您必须使用较低版本
    【解决方案2】:

    我找到了两个解决方案来消除这个错误,但我不知道哪个最正确

    I) 下载版本,为此您必须使用版本 25 而不是 26 修改 build.gradle,如下所示:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 25
        buildToolsVersion "26.0.1"
        defaultConfig {
            applicationId "xx.xx.xx.seguros"
            minSdkVersion 9
            targetSdkVersion 25
            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.+'
        compile 'com.android.support:design:25.+'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        testCompile 'junit:junit:4.12'
    }
    

    II) 使用tools: overrideLibrary,您必须通过添加以下内容来修改清单:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="es.uv.lisitt.seguros"
        xmlns:tools="http://schemas.android.com/tools">
    
        <uses-sdk tools:overrideLibrary="android.support.design, android.support.v7.appcompat,android.support.graphics.drawable, android.support.v7.recyclerview, android.support.v4, android.support.mediacompat, android.support.fragment, android.support.coreui, android.support.coreutils, android.support.compat"/>
    
         .....
    </manifest>
    

    【讨论】:

      【解决方案3】:
      apply plugin: 'com.android.application'
      
      android {
      compileSdkVersion 26
      buildToolsVersion "26.0.0" //change 
      defaultConfig {
          applicationId "xx.xx.xx.seguros"
          minSdkVersion 14 //change
          targetSdkVersion 26
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
         }
      
      }
      

      希望对你有帮助

      【讨论】:

      • 感谢您的回答!如果我想将 sdk min 保持在 9?
      • 我认为 sdk-9 不包括导航抽屉
      • 您可以参考this
      • 我尝试使用 min sdk 9 的 25 版,它与导航抽屉配合得很好
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-01
      相关资源
      最近更新 更多