android - 如何确定 Android 构建错误 "failed linking file resources"发生的原因?

标签 android build.gradle

我的 Android Studio 项目抛出了这个错误。它来得很突然。我不知道这是什么。

我已经尝试了所有可能的方法,但根本不起作用。它工作正常,但当我尝试在手机中测试该应用程序时突然出现这种情况。它向我展示了这个错误。我已经重建了项目并重新启动了 Android Studio 我已经尝试了互联网上所有可能的解决方案,但没有一个对我有用。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
  Output:  C:\Charcha2\app\src\main\res\layout\activity_main.xml:16: error: attribute fabAttached (aka global.alyssum.charcha:fabAttached) not found.
  error: failed linking file resources.

  Command: C:\Program Files\android-studio\gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\139903147407266fe3b81c96769c0caf\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
          C:\ANDROID\NEWFOLDER\SDK\platforms\android-28\android.jar\
          --manifest\
          C:\Charcha2\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
          -o\
          C:\Charcha2\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
          -R\
          @C:\Charcha2\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
          --auto-add-overlay\
          --java\
          C:\Charcha2\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
          --custom-package\
          global.alyssum.charcha\
          -0\
          apk\
          --output-text-symbols\
          C:\Charcha2\app\build\intermediates\symbols\debug\R.txt\
          --no-version-vectors
  Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
  Output:  C:\Charcha2\app\src\main\res\layout\activity_main.xml:16: AAPT: error: attribute fabAttached (aka global.alyssum.charcha:fabAttached) not found.

  error: failed linking file resources.
  Command: C:\Program Files\android-studio\gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\139903147407266fe3b81c96769c0caf\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
          C:\ANDROID\NEWFOLDER\SDK\platforms\android-28\android.jar\
          --manifest\
          C:\Charcha2\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
          -o\
          C:\Charcha2\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
          -R\
          @C:\Charcha2\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
          --auto-add-overlay\
          --java\
          C:\Charcha2\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
          --custom-package\
          global.alyssum.charcha\
          -0\
          apk\
          --output-text-symbols\
          C:\Charcha2\app\build\intermediates\symbols\debug\R.txt\
          --no-version-vectors
  Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

这是主要 Activity XML 代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomAppBar"
            style="@style/Widget.MaterialComponents.BottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:backgroundTint="#fff"
            app:fabAttached="true"
            app:fabCradleRoundedCornerRadius="16dp">

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="30dp"
                app:srcCompat="@drawable/home" />


            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="45dp"
                app:layout_anchor="@id/bottomAppBar"
                app:srcCompat="@drawable/deals" />

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="95dp"
                app:srcCompat="@drawable/listing" />


            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="45dp"
                app:srcCompat="@drawable/profile" />


        </com.google.android.material.bottomappbar.BottomAppBar>


        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fabSize="normal"
            android:src="@drawable/addvideo"
            app:backgroundTint="#fff"
            app:layout_anchor="@+id/bottomAppBar"
            android:scaleType="center"
            android:id="@+id/myFab"
            />

        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:id="@+id/toolBar"
            android:background="@drawable/grey_border_top">


            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/city"
                android:foregroundGravity="left"/>

            <EditText
                android:layout_width="180dp"
                android:layout_height="23dp"
                android:layout_marginStart="40dp"
                android:background="@drawable/search_border"
                android:hint="Search videos..."
                android:padding="3dp"
                android:textStyle="italic" />

            <ImageView
                android:layout_width="21dp"
                android:layout_height="21dp"
                android:src="@drawable/search"
                android:layout_marginStart="7dp"
                />

            <TextView
                android:id="@+id/changeLang"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:clickable="true"
                android:onClick="onClick"
                android:text="Change Language"
                android:textColor="@android:color/black" />

        </androidx.appcompat.widget.Toolbar>

        <com.google.android.material.tabs.TabLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="?attr/actionBarSize"
            android:id="@+id/tab_layout">

        </com.google.android.material.tabs.TabLayout>


        <androidx.viewpager.widget.ViewPager
            android:layout_width="match_parent"
            android:layout_marginTop="?attr/actionBarSize"
            android:layout_height="360dp"
            android:id="@+id/viewPager"/>


    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</LinearLayout>

这是我的 gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "global.alyssum.charcha"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0-alpha1'
    implementation 'com.google.android.gms:play-services-ads:15.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.support:design:28.0.0'
    implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
}

这是我的主要 Activity

package global.alyssum.charcha;


import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
//import android.widget.Toolbar;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import global.alyssum.charcha.adapter.PagerAdapter;

public class MainActivity extends AppCompatActivity {

    Toolbar AGS_toolbar;
    TextView AGS_langChangeTextView;
    FloatingActionButton AGS_Fab;
    private TabLayout AGS_tabLayout = null;
    private ViewPager AGS_viewPager = null;

    public void onClick(View view) {

        Toast.makeText(MainActivity.this, "Language changed.", Toast.LENGTH_SHORT).show();

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AGS_toolbar = (Toolbar) findViewById(R.id.toolBar);
        AGS_langChangeTextView = (TextView)findViewById(R.id.changeLang);
        AGS_Fab = (FloatingActionButton) findViewById(R.id.myFab);
        AGS_tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        AGS_viewPager = (ViewPager) findViewById(R.id.viewPager);


        final PagerAdapter adapter = new global.alyssum.charcha.adapter.PagerAdapter(getSupportFragmentManager(),AGS_tabLayout.getTabCount());
        AGS_viewPager.setAdapter(adapter);

    }


}

这是 list 文件。

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

    <uses-permission android:name="android.permission.INTERNET" />

    <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=".Splash"
            android:theme="@style/splash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity"
            android:theme="@style/splash">

        </activity>
    </application>

</manifest>

最佳答案

在此:
https://material.io/develop/android/components/bottom-app-bar/
还有这个:
https://developer.android.com/reference/com/google/android/material/bottomappbar/package-summary
没有提及 fabAttached 属性。
相反,第一个链接指出:

The FloatingActionButton can be anchored to the BottomAppBar by setting app:layout_anchor or by calling CoordinatorLayout.LayoutParams#setAnchorId(int)

所以删除这个属性:

app:fabAttached="true"

关于android - 如何确定 Android 构建错误 "failed linking file resources"发生的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53913333/

相关文章:

android - 从 ImageView 获取裁剪后的图像

java - 安卓工作室 : UNEXPECTED TOP-LEVEL EXCEPTION:

android - 如何将日期构建附加到 gradle 上的 versionNameSuffix

java - 滑动回收站 View 无法正常工作

android - 检查 Android 应用程序中是否使用了库

android - 更新了Android Studio 3.0 Stable之后,我在新的Gradle中迁移了项目,而在构建时遇到了问题

Android:没有父类(super class)的类型:模块信息

java - 检查对象是否属于类型

android - ionic 框架 : Exporting Project To APK

java - 如何更新每个循环中的数据而不是在 Android 中一次显示所有循环数据