2

My Android Studio project is throwing out this error. It came all of a sudden. I've no idea what this is.

I've tried every possible ways but its not working at all. It was working fine but suddenly when I tried to test the app in the phone. It showed me this error. I have already rebuild the project and restarted Android Studio I've tried every possible solution on the internet but none of them worked for me.

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.

Here is the main activity XML code.

<?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>

And here is my gradle file

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'
}

Here is my mainActivity

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);

    }


}

And this is the manifest files.

<?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>
halfer
  • 19,824
  • 17
  • 99
  • 186
Aunkit Chaki
  • 43
  • 2
  • 9

2 Answers2

3

In this:
https://material.io/develop/android/components/bottom-app-bar/
and this:
https://developer.android.com/reference/com/google/android/material/bottomappbar/package-summary
there is no mention of the fabAttached attribute.
Instead the 1st link states:

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

so remove this attribute:

app:fabAttached="true"
forpas
  • 160,666
  • 10
  • 38
  • 76
1

I have just had a very similiar problem.

Check if you can locate the resource file 'R' in one of the java subfolders of your project. It sounds as if the location of the resourc file cannot be determined. If you cant locate it, it might be deleted off and that may be the reason why there is a linking error. In my case it got deleted when I created a Google Maps activity.

If you cannot locate it: Try: Build -> Clean Project That cleans the gradle file

Alternatively: File->Invalidate Caches Then sync the project with gradle files

Give these a go and see if it changes anything. It may restore the resource file. If it doesnt, I would suggest creating a new project and copying and pasting the code from the 'old' project into the new one. This way you can make sure the resource file is restored and it should eliminate the linking error. You'd have to create all xml files and java classes again, but depending on the size of your project it might be faster than trying to restore the resource file.

Julia
  • 111
  • 10