java - Android Studio找不到资源且资源链接失败

标签 java android linker android-resources aapt2

最近我在使用 AAPT2 时遇到了问题。该问题是由我的用户名包含非 ASCII 字符引起的。我创建了另一个 Windows 帐户(没有非 ASCII 字符)并在其上安装了 Android Studio。然后我打开了我的旧项目,当 AS 要求我更新时我同意了。现在,当我尝试构建我的应用程序时,我收到以下错误:

Android resource linking failed D:\Android_Studio\Praca\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found. D:\Android_Studio\Praca\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found. D:\Android_Studio\Praca\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2970: error: resource android:attr/fontVariationSettings not found. D:\Android_Studio\Praca\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2971: error: resource android:attr/ttcIndex not found. error: failed linking references.

我在 StackOverflow 发现的大多数帖子都表明这个问题可能与支持库有关,他们说版本可能是错误的。我怎样才能更改版本?我的项目也使用 OpenCV 库,它的配置可能无效。 我已经尝试过清理和重建项目并在 Gradle 中调整compileSDKVersion。

这是values-v28.xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.Theme.AppCompat" parent="Base.V28.Theme.AppCompat"/>
<style name="Base.Theme.AppCompat.Light" parent="Base.V28.Theme.AppCompat.Light"/>
<style name="Base.V28.Theme.AppCompat" parent="Base.V26.Theme.AppCompat">
    <!-- We can use the platform styles on API 28+ -->
    <item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
</style>
<style name="Base.V28.Theme.AppCompat.Light" parent="Base.V26.Theme.AppCompat.Light">
    <!-- We can use the platform styles on API 28+ -->
    <item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
</style>

这是 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kawa.praca">

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />

<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Powitanie">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Trening" />
    <activity android:name=".Zdjecia" />

    <provider
        android:name=".DbProvider"
        android:authorities="com.example.kawa.praca"
        android:exported="true" />
    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.android.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

    <activity android:name=".AddActivity" />
    <activity android:name=".UserPanel" />
    <activity android:name=".ScoringPanel" />
    <activity android:name=".Scoring" />
    <activity android:name=".NewPlanActivity" />

    <receiver
        android:name=".PlanReceiver"
        android:enabled="true"
        android:exported="true" />

    <activity android:name=".ChartsActivity"></activity>
</application>

</manifest>

下面是我的 build.gradle 文件应用程序模块。在此文件中,带有支持库的子条款“依赖项”条目带有下划线,AS 向我显示警告:

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:customtabs:26.1.0

我尝试将版本更改为较新或较旧的版本,但此警告仍然出现。

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.kawa.praca"
    minSdkVersion 24
    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'
    }
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } 
}
// Encapsulates your external native build configurations.
externalNativeBuild {

    // Encapsulates your CMake build configurations.
    cmake {

        // Provides a relative path to your CMake build script.
        path "../CMakeLists.txt"
    }
}
//buildToolsVersion '27.0.3'
buildToolsVersion '28.0.3'
productFlavors {
}
}

repositories {
maven { url 'https://jitpack.io' }
}

dependencies {
//implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:customtabs:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso- 
core:3.0.1'
implementation project(':openCVLibrary340')
//implementation 'com.jjoe64:graphview:4.2.2'
}

dependencies {
implementation 'com.android.support.constraint:constraint-layout:+'
}

最佳答案

我通过将compilesdkversion更新为28修复了同样的错误,因为目前我的构建工具版本是28.0.3,因此版本应该与完美构建相同。 另请检查您的实现“com.android.support:appcompat-v7:28.0.0” 将各自的依赖版本更改为28,这样可以防止运行时崩溃

关于java - Android Studio找不到资源且资源链接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56309209/

相关文章:

java - 从绝对路径转换为相对路径

java - 如何导入 jboolexpr-src-1.2.jar?

android - 是否可以在 Android 的可绘制对象中使用子文件夹?

linker - 如何使用 gnatmake 或在 Ada 代码中将 Ada 库链接到 .adb 文件

ios - 架构armv7的 undefined symbol :homeViewController1

c++ - 如何将 DLL 链接到我的项目?错误 LNK2019 : unresolved external symbol

java - tomcat7 上的 servlet eclipse HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST

java - j_spring_security_check 404 问题

java - android 线程和处理程序 - 从后台线程更改 UI 对象

android - 您的设备似乎不支持相机