升级到Android-P后无法构建项目

11

以下是我收到的错误:

C:\Users\Dell\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0-alpha1.aar\51cd62c84e9404bd66ab4daf252c48a1\res\values-v28\values-v28.xml
Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.
C:\Users\Dell\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0-alpha1.aar\51cd62c84e9404bd66ab4daf252c48a1\res\values\values.xml
Error:(252, 5) error: resource android:attr/fontVariationSettings not found.
Error:(252, 5) error: resource android:attr/ttcIndex not found.
E:\20thJune2017_7PM\trunk\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml
Error:(11) error: resource android:attr/dialogCornerRadius not found.
Error:(7) resource android:attr/dialogCornerRadius not found.
Error:(11) resource android:attr/dialogCornerRadius not found.
E:\20thJune2017_7PM\trunk\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Error:(486) resource android:attr/fontVariationSettings not found.
Error:(486) resource android:attr/ttcIndex not found.
Error:failed linking references.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt

以下是我的 build.gradle (应用程序级别)

   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:+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
    compile 'com.android.support:design:+'
    compile 'com.android.support:support-v4:+'
    testCompile 'junit:junit:4.12'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.google.code.gson:gson:2.7'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.fiskurgit:ChipCloud:2.1.1'
    compile 'com.google.android.gms:play-services-maps:11.4.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.0'
    compile 'commons-codec:commons-codec:1.10'
    compile 'com.crittercism:crittercism-android-agent:+'
    compile 'ch.hsr:geohash:1.3.0'
    compile 'com.google.firebase:firebase-messaging:11.4.0'
    compile 'com.google.firebase:firebase-core:11.4.0'
    compile 'com.google.android.gms:play-services-analytics:11.4.0'
    compile 'com.ahmedjazzar.rosetta:rosetta:1.0.1'
}

我尝试了StackOverflow上的不同解决方案,但没有一个有效。您可以帮助我吗?谢谢。


你尝试过这里提供的解决方案吗?(https://dev59.com/qFUM5IYBdhLWcg3wMeAk) - Jordan
https://developer.android.com/preview/setup-sdk.html - Sira Lam
嗨Jirdan,是的,通过提到的解决方案APK正在构建,但它显示“应用程序未安装”(调试和发布都是如此)。在使用您指定的链接构建APK之后,https://dev59.com/2qnka4cB1Zd3GeqPSrqQ - Naveen
请将以下与编程相关的内容从英文翻译成中文。只返回翻译后的文本:请包括您在gradle文件中的依赖项块。 - laalto
我无法添加依赖项。 - Naveen
显示剩余3条评论
8个回答

20

我已经在这里回答了一个类似的问题。

尝试将compileSdkVersion改为:

compileSdkVersion 28

这些属性是在此版本中添加的。请查看此处此处此处


我已经修改了28个,但仍然无法工作。错误:1. 错误:未找到资源android:attr/dialogCornerRadius。 2. 错误:未找到资源android:attr/dialogCornerRadius。 3. AAPT:错误:未找到资源android:attr/fontVariationSettings。 4. AAPT:错误:未找到资源android:attr/ttcIndex。 - Sathvik Nasani
你找到解决方案了吗? - pinturic
我的compileSdkVersion已经是28了,但我仍然遇到了问题。我所做的是迁移AndroidX(Refactor -> Migrate to AndroidX)。你能否建议一下问题出在哪里以及如何解决?链接错误:\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml - sssvrock

3

删除这些行并同步:

compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:design:+'
compile 'com.android.support:support-v4:+'

然后进入文件 -> 项目结构

然后进入依赖项,点击右上角的 + 按钮

从列表中选择库依赖项。选择上述三个依赖项并点击确定

确保 compileSdkVerison 和 targetSdkVersion 与这些依赖项相同。


嗨,Nitesh,我尝试了上面指定的解决方案,但没有奏效。出现了“未安装应用程序”的错误。你能帮我吗? - Naveen
是的,我无法解决这个问题。我已经尝试了两天。 - Naveen
在这些依赖项之前添加此行代码并尝试: //noinspection GradleCompatible - Nitesh Lekhi
@NiteshLekhi永远不要使用“+”添加依赖项,而是使用特定或精确的依赖版本。这样你的构建就可以被重现,当你的代码由于某种原因不能与最新版本一起工作时,你仍然可以构建和使用上一个可用的版本。它将帮助你避免讨厌的问题并节省大量时间。之后你会感谢我的;) - Ewoks

2

我遇到了类似的问题,解决方法是迁移到AndroidX。

With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

If you have any Maven dependencies that have not been migrated to the AndroidX namespace, the Android Studio build system also migrates those dependencies for you when you set the following two flags to true in your gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

To migrate an existing project that does not use any third-party libraries with dependencies that need converting, you can set the android.useAndroidX flag to true and the android.enableJetifier flag to false.

.


我的compileSdkVersion已经是28了,但我仍然遇到了问题。我所做的是迁移AndroidX(Refactor -> Migrate to AndroidX)。你能否建议一下问题出在哪里以及如何解决?链接错误:\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml - sssvrock

2

你需要使用更具体的依赖版本

compile 'com.android.support:design:+'

选择最新的设计支持库(28.0.0-alpha),该库与您的编译SDK版本<28不兼容。请更改为

compile 'com.android.support:design:27.+'

最好是具体版本,例如

compile 'com.android.support:design:27.1.0'

同样适用于您的其他动态依赖项,其版本中包含+


嗨,laalto,使用上述指定的代码无法工作。你能帮我解决这个问题吗? - Naveen
如果你想使用最新的支持库,也可以将compileSdkVersion更新为28。 - Izabela Orlowska

1
如果你仍然遇到这个问题,请尝试在终端中进行调试。出现此错误的原因有很多,但除非你进行详细调试,否则无法确定确切原因。 在终端中运行此命令,你可能会知道你在哪里遇到了这个bug: ./gradlew installDebug

0

尝试这个:

前往gradle(模块)的依赖项,并将所有依赖项替换为以下内容:

dependencies {
  debugImplementation 'com.android.support.constraint:constraint-layout:1.1.2'
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  androidTestImplementation 'junit:junit:4.12'
  implementation 'com.android.support:appcompat-v7:26.1.0'
  implementation 'com.android.support:support-v4:26.1.0'
  implementation 'com.android.support:design:26.1.0'
}

将所有的SdkVersion更改为26

然后在compileSdkVersion下添加以下内容:

buildToolsVersion '27.0.3'

0

查看您的编译SDK版本,我的是API:26:Android 8.0

然后在您的Build.gradle Module: app中更改以下内容:

->>>格式: 实施 'com.android.support:design:28.0.0-beta1'

implementation 'com.android.support:cardview-v7:28.0.0-beta1'
implementation 'com.android.support:recyclerview-v7:28.0.0-beta1'
implementation 'com.android.support:appcompat-v7:28.0.0-beta1'

->>>转换为: 实现 'com.android.support:design:26.0.0-beta1'

implementation 'com.android.support:cardview-v7:26.0.0-beta1'
implementation 'com.android.support:recyclerview-v7:26.0.0-beta1'
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'

祝你有美好的一天...


0

对我来说,只需进入应用程序级别的build.gradle文件并将targetsdk级别更改为推荐级别即可解决此问题


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接