Android Studio gradle 不编译指定版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24444196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio gradle doesn't compile the specified version
提问by Thahzan
I've been developing this small project for some days now but suddenly today, Android Studio started to give me this error
我已经开发这个小项目好几天了,但今天突然间,Android Studio 开始给我这个错误
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 14 declared in library com.android.support:support-v4:21.0.0-rc1
I understood that it is because it's trying to compile the library of Android-L. The version I want it to compile is the old version but it won't. It keeps giving me the above error no matter which version I enter. Here is the dependencies.
我了解到这是因为它正在尝试编译Android-L的库。我希望它编译的版本是旧版本,但不会。无论我输入哪个版本,它都会不断给我上述错误。这是依赖项。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.android.support:support-v4:20.+'
}
UPDATE
更新
I just installed Android Studio Beta and changed my dependencies to the one Eugen suggested below. But syncing the project gives the same error no matter which version of appcompat, support version I specify. It gives this error every single time I sync
我刚刚安装了 Android Studio Beta 并将我的依赖项更改为下面 Eugen 建议的依赖项。但是无论我指定的 appcompat 和支持版本是哪个版本,同步项目都会出现相同的错误。每次同步时都会出现此错误
uses-sdk:minSdkVersion 14 cannot be smaller than version L declared in library com.android.support:support-v4:21.0.0-rc1
My updated dependencies
我更新的依赖项
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.+'
}
UPDATE 2
更新 2
I don't think I understand the dependencies system of Android Studio correctly. I just removed both the appcompat and support from the dependencies and it still gives me the same error. Do I have to remove the initially included libraries from somewhere?
我认为我没有正确理解 Android Studio 的依赖系统。我刚刚从依赖项中删除了 appcompat 和 support ,它仍然给我同样的错误。我是否必须从某个地方删除最初包含的库?
build.gradle
构建.gradle
*note - I added those two libraries back in again and tried syncing, just in case. But no chenges.
*注意 - 我再次添加了这两个库并尝试同步,以防万一。但没有成吉思汗。
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "taz.starz.footynews"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.+'
compile project(':ParallaxScroll')
compile files('src/main/libs/Header2ActionBar-0.2.1.jar')
compile 'com.arasthel:gnavdrawer-library:+'
compile 'com.koushikdutta.ion:ion:1.2.4'
}
Top level build.gradle
顶级 build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
回答by TalkLittle
UPDATE:Found the real fix for my case. Make sure none of your dependencies are silently including support-v4 r21 by doing this in your build.gradle
:
更新:为我的案例找到了真正的解决方案。通过在您的build.gradle
.
compile("com.blahblah:blah:123") {
exclude group: 'com.android.support', module:'support-v4'
}
You can add the exclude
to all libraries, then remove one-by-one until you figure out which one was pulling in support-v4
and giving you the error. And leave exclude
on that one.
您可以将其添加exclude
到所有库中,然后一个一个地删除,直到您找出哪个库被拉入support-v4
并给出错误为止。离开exclude
那个。
There is a new bug filed here: https://code.google.com/p/android/issues/detail?id=72430
这里有一个新的错误:https: //code.google.com/p/android/issues/detail?id=72430
Assuming you are using the Support Repository, the workaround is to comment or remove the line
假设您正在使用 Support Repository,解决方法是注释或删除该行
<version>21.0.0-rc1</version>
in the local Maven repo listing file at <android-sdk>/extras/android/m2repository/com/android/support-v4/maven-metadata.xml
在本地 Maven 存储库列表文件中 <android-sdk>/extras/android/m2repository/com/android/support-v4/maven-metadata.xml
回答by Gabriele Mariotti
With the last updates, using this:
随着最后的更新,使用这个:
compile 'com.android.support:support-v4:20.+'
or
或者
compile 'com.android.support:support-v4:+'
you are using the support lib in L-preview.
您正在L-preview中使用支持库。
These support libs are declaring minSdkVersion L
.
这些支持库正在声明minSdkVersion L
.
You have to force the minSdkVersion
to be 'L' (check the doc)
您必须强制将minSdkVersion
其设为“L”(查看文档)
This is because these APIs are not final. It is a way to prevent installing the apps on a final API 21 device or publishing it on the store using support lib 21-r1.
这是因为这些 API 不是最终版本。这是一种防止在最终 API 21 设备上安装应用程序或使用 support lib 21-r1 在商店上发布应用程序的方法。
Using
使用
compile 'com.android.support:support-v4:19.1.0'
you are using the "old" support library 19.1.0.
您正在使用“旧”支持库 19.1.0。
回答by raycohen
I had the same issue as one of my dependencies had specified 'support-v7:+' as a dependency. I was able to track this down using gradle dependencies
我遇到了同样的问题,因为我的一个依赖项将“support-v7:+”指定为依赖项。我能够使用gradle dependencies
Gradle provides a way to force resolutionto a specific version. I ended up having this in my build.grade
:
Gradle 提供了一种强制解析特定版本的方法。我最终在我的build.grade
:
compile('com.android.support:appcompat-v7:19.1.0') {
// really use 19.1.0 even if something else resolves higher
force = true
}
回答by For Guru
compile('com.android.support:support-v4:19.1.0'){
force = true
}
This worked for me
这对我有用
回答by IgorGanapolsky
I was getting the error:
我收到错误:
Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 1 cannot be smaller than version 4 declared in library C:\Users\Igor\AppData\Local\Android\sdk\samples\android-21_1\legacy\ApiDemos\app\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\AndroidManifest.xml Suggestion: use tools:overrideLibrary="android.support.v4" to force usage
任务“:app:processDebugManifest”执行失败。
清单合并失败:uses-sdk:minSdkVersion 1 不能小于库 C:\Users\Igor\AppData\Local\Android\sdk\samples\android-21_1\legacy\ApiDemos\app\build\intermediates\ 中声明的版本 4 exploded-aar\com.android.support\support-v4\21.0.3\AndroidManifest.xml 建议:使用 tools:overrideLibrary="android.support.v4" 强制使用
Then I resolved it by putting the following in my defaultConfiggradle block:
然后我通过将以下内容放在我的defaultConfiggradle 块中来解决它:
minSdkVersion 15
targetSdkVersion 21
回答by Eugen Martynov
That is correct. The new support library is not compatible (yet) with old Android versions.
那是正确的。新的支持库(尚)与旧的 Android 版本不兼容。
Change your gradle to:
将您的gradle更改为:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.1.+'
compile 'com.android.support:support-v4:19.1.+'
}
I hope your still have something like this:
我希望你还有这样的事情:
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
}
回答by mamont
In Android SDK Manager install "Android Support Repository" from "extra" group. It helps me. When I added "exclude group: 'com.android.support', module:'support-v4'" build was completed, but some other errors was occured
在 Android SDK Manager 中,从“extra”组安装“Android Support Repository”。它帮助到我。当我添加“排除组:'com.android.support',模块:'support-v4'”构建完成,但发生了一些其他错误