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

查看:33
本文介绍了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 中,targetSdkVersion 和 minSdkVersion 标志是在 build.gradle 文件中定义的.该项目是使用 Android Studio 的新建项目"向导创建的,我的代码的 AndroidManifest.xml 中没有标签.所以问题不应该是两个值不同步.根据上面的消息,main manifest中的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中更改targetSdkVersionminSdkVersion

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.

第一步

打开 build.gradle - *Path\Your_Application\app\build.gradle*

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

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

更改 targetSdkVersion &minSdkVersion 值您想要的值.

Change targetSdkVersion & minSdkVersion values to what you desire.

第 2 步

在Android stuido菜单中找到Build"( alt + b @ windows )并选择Clean project"

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天全站免登陆