Android Studio:更改targetSdkVersion的正确方法是什么? [英] Android Studio: What is the right way to change targetSdkVersion?

查看:1505
本文介绍了Android Studio:更改targetSdkVersion的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android Studio(不是Eclipse)中将targetSdkVersion从19更改为18,但是失败了.

I want to change the targetSdkVersion from 19 to 18 in Android Studio (not Eclipse), but failed.

我更改了targetSdkVersion,并使用Gradle文件重新同步项目后,Android Studio抱怨以下内容:

Android Studio complains the following after I changed the targetSdkVersion, and resync the project with Gradle files:

Execution failed for task ':(project name):processDebugManifest'.
> Manifest merging failed. See console for more info.

从控制台中,我发现它是使用旧的targetSdkVersion值添加到gradle依赖项中的库.

From the console I found that it is the library I added to the gradle dependencies using the old targetSdkVersion value.

[(Code Directory)\main\AndroidManifest.xml, (Code Directory)\build\exploded-bundles\(Library Directory).aar\AndroidManifest.xml:2] Main manifest has <uses-sdk android:targetSdkVersion='18'> but library uses targetSdkVersion='19'

我了解到,在Android Studio中,在build.gradle文件中定义了targetSdkVersion和minSdkVersion标志.该项目是使用Android Studio的新建项目"向导创建的,在我的代码的AndroidManifest.xml中没有标记.因此,问题不应该是两个值不同步.根据以上消息,主清单中的targetSdkVersion值就是我想要的.

I learn that in Android Studio, the targetSdkVersion and minSdkVersion flags are defined in the build.gradle file. The project is created with Android Studio's "New project" wizard, and there is NO tag in my code's AndroidManifest.xml. So the problem should not be the two values out of sync. According to the above message, the targetSdkVersion value in the main manifest is what I want.

因此,问题应该出在库的清单文件中.我打开库的AndroidManifest.xml文件,发现以下行:

So the problem should be in the manifest file of the library. I open the library's AndroidManifest.xml file and found the following line:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>

显然这是不正确的.问题是该文件不用于手动修改.我尝试更改targetSdkVersion值,甚至尝试删除该声明,但每次构建项目时都会返回.

Obviously it isn't correct. The problem is that the file is not for manual modification. I tried changing the targetSdkVersion value, and even tried removing the declaration, but it comes back every time I build the project.

我尝试清理项目,但还是没有运气.

I tried cleaning the project, still no luck.

所以我的问题是:在我不知道的Android Studio中,有没有一种正确"的方法来更改targetSdkVersion?

So my question is: Is there a "right" way to alter the targetSdkVersion in Android Studio which I am not aware of?

推荐答案

如何在Android Studio中更改 targetSdkVersion minSdkVersion

How to change targetSdkVersion and minSdkVersion in Android studio

有相同的问题,但要在几个小时后将其钉牢.

Did have the same issue but mange to nail it down after a couple of hours.

第1步

打开build.gradle-*路径\您的应用程序\ app \ build.gradle *

Open build.gradle - *Path\Your_Application\app\build.gradle*

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}

更改目标minSdkVersion值可以满足您的需求.

Change targetSdkVersion & minSdkVersion values to what you desire.

第2步

在Android stuido菜单中找到构建"(alt + b @ Windows),然后选择清理项目"

In Android stuido menu find "Build" ( alt + b @ windows ) and choose "Clean project"

希望这可以帮助其他遇到相同问题的人.

Hope this help others with the same issue.

这篇关于Android Studio:更改targetSdkVersion的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆