Home > Software design >  Android Studio/Java: Android resource linking failed & error: failed linking references
Android Studio/Java: Android resource linking failed & error: failed linking references

Time:01-08

My friend pushed her code to my repo, and when I run an emulator it generates the error message:

Android resource linking failed

wia2007.example.healthier_app-mergeDebugResources-45:/values/values.xml:8579: error: expected reference but got (raw string) null.

error: failed linking references.

What's frustrating is that it doesn't explain which line explicitly trigger this error, and the code has no error warnings whatsoever.

I've tried changing build.gradle implementation but failed, and I've made sure there is no errors on any of my .xml files. What other possibilities can happen?

I'm expecting my emulator can run without errors since there's no error warnings up until the runtime.

Let me know what files that I should share the code for more dissection. 1 2 3 4 5 6

I don't know how to reproduce the errors, but currently I narrowed down my error files to 4 xml files:

fragment_earn_reward_t.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/bg_tracker_activity">

    <TextView
        android:id="@ id/level_TV"
        style="@style/small_font"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="21dp"
        android:text="@string/level"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@ id/which_level_TV"
        style="@style/small_font"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_marginTop="21dp"
        android:text="20"
        app:layout_constraintStart_toEndOf="@id/level_TV"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@ id/reward_TV"
        style="@style/small_font"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_marginTop="21dp"
        android:text="@string/reward"
        app:layout_constraintStart_toEndOf="@id/which_level_TV"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@ id/reward_type"
        style="@style/small_font"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginTop="21dp"
        android:text="@string/profile_title"
        android:textColor="@color/red"
        app:layout_constraintStart_toEndOf="@ id/reward_TV"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@ id/the_reward"
        style="@style/reward_style"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginTop="15dp"
        android:padding="5dp"
        android:text="@string/expert_dietitian"
        app:layout_constraintStart_toEndOf="@ id/reward_type"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@ id/current_progress_TV"
        style="@style/small_font"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="20dp"
        android:text="@string/current_progress"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/which_level_TV" />

    <LinearLayout
        android:id="@ id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="15dp"
        android:layout_marginEnd="31dp"
        android:background="@drawable/reward_activity_item"
        android:gravity="center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/current_progress_TV">

        <ProgressBar
            android:id="@ id/progressBar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="260dp"
            android:layout_height="40dp"
            android:layout_marginEnd="20dp"
            android:progressBackgroundTint="#bdbdbd"
            android:progressTint="#44DA37"
            android:scaleY="3"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20%"
            android:textColor="@color/black"
            android:textSize="18sp"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginEnd="31dp"
        android:dividerPadding="3dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/linearLayout">

        <TextView
            android:id="@ id/level_TV_2"
            style="@style/small_font_italic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="2.5dp"
            android:text="@string/next_level"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@ id/which_level_TV_2"
            style="@style/small_font_italic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="2.5dp"
            android:text="21"
            app:layout_constraintStart_toEndOf="@id/level_TV"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@ id/reward_TV_2"
            style="@style/small_font_italic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="2.5dp"
            android:text="@string/reward"
            app:layout_constraintStart_toEndOf="@id/which_level_TV"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@ id/reward_type_2"
            style="@style/small_font_italic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="2.5dp"
            android:text="@string/sticker_chat"
            android:textColor="@color/red"
            app:layout_constraintStart_toEndOf="@ id/reward_TV"
            app:layout_constraintTop_toTopOf="parent" />

    </LinearLayout>

    <TextView
        android:id="@ id/reward_activity_TV"
        style="@style/small_font"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="150dp"
        android:text="Reward Activity:"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/which_level_TV" />

    <LinearLayout
        android:id="@ id/reward_activity_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="15dp"
        android:layout_marginEnd="31dp"
        android:background="@drawable/reward_activity_item"
        android:gravity="center"
        android:paddingHorizontal="20dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/reward_activity_TV">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Run 2km"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginHorizontal="5dp"
            android:backgroundTint="@color/white"
            android:src="@drawable/ic_baseline_check_24" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginHorizontal="5dp"
            android:backgroundTint="@color/white"
            android:src="@drawable/ic_baseline_close_24" />
    </LinearLayout>

    <LinearLayout
        android:id="@ id/reward_activity_item_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="31dp"
        android:background="@drawable/reward_activity_item"
        android:gravity="center"
        android:paddingHorizontal="20dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/reward_activity_item">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Drink 6 cups of water"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginHorizontal="5dp"
            android:backgroundTint="@color/white"
            android:src="@drawable/ic_baseline_check_24" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginHorizontal="5dp"
            android:backgroundTint="@color/white"
            android:src="@drawable/ic_baseline_close_24" />
    </LinearLayout>

    <LinearLayout
        android:id="@ id/reward_activity_item_3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="31dp"
        android:background="@drawable/reward_activity_item"
        android:gravity="center"
        android:paddingHorizontal="20dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/reward_activity_item_2">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Skip ice cream for a day"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginHorizontal="5dp"
            android:backgroundTint="@color/white"
            android:src="@drawable/ic_baseline_check_24" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginHorizontal="5dp"
            android:backgroundTint="@color/white"
            android:src="@drawable/ic_baseline_close_24" />

    </LinearLayout>

    <androidx.appcompat.widget.AppCompatImageButton
        android:id="@ id/appCompatImageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="31dp"
        android:backgroundTint="@color/tracker_submit_darkerPink"
        android:src="@drawable/ic_baseline_add_24"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/reward_activity_item_3" />

    <TableLayout
        android:id="@ id/TL_reward_history"
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="31dp"
        android:layout_marginTop="30dp"
        android:layout_marginEnd="31dp"
        android:stretchColumns="*"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/appCompatImageButton">


        <TableRow
            android:id="@ id/TRExercise1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@ id/TVTable3TitleName"
                android:layout_width="172dp"
                android:layout_height="wrap_content"
                android:background="@color/tracker_submit_darkerPink"
                android:gravity="center"
                android:padding="10dp"
                android:text="See Rewards History"
                android:textStyle="bold"
                android:textColor="@color/white" />

        </TableRow>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TableRow
                    android:id="@ id/TRExercise2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@drawable/border_white">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:padding="10dp"
                            android:text="Profile icon"
                            android:textColor="@color/black"
                            android:textSize="12sp" />

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:src="@drawable/profile_tracker_reward" />


                    </LinearLayout>

                    <TextView
                        android:id="@ id/TVTable3Time1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:background="@drawable/border_white"
                        android:padding="10dp"
                        android:text="Level. 19 Reward"
                        android:textColor="@color/black"
                        android:textSize="12sp"
                        android:textStyle="italic" />
                </TableRow>

                <TableRow
                    android:id="@ id/TRExercise3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@drawable/border_white">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:padding="10dp"
                            android:text="Sticker chat"
                            android:textColor="@color/black"
                            android:textSize="12sp" />

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:src="@drawable/lunges_tracker_reward" />


                    </LinearLayout>

                    <TextView
                        android:id="@ id/TVTable3Time2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:background="@drawable/border_white"
                        android:padding="10dp"
                        android:text="Level. 18 Reward"
                        android:textColor="@color/black"
                        android:textSize="12sp"
                        android:textStyle="italic" />
                </TableRow>

                <TableRow
                    android:id="@ id/TRExercise4"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@ id/TVTable3Name3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@drawable/border_white"
                        android:padding="10dp"
                        android:text="Free coaching subscription (1 DAY) "
                        android:textColor="@color/black"
                        android:textSize="12sp" />

                    <TextView
                        android:id="@ id/TVTable3Time3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:background="@drawable/border_white"
                        android:padding="10dp"
                        android:text="Level. 17 Reward"
                        android:textColor="@color/black"
                        android:textSize="12sp"
                        android:textStyle="italic" />
                </TableRow>
            </androidx.appcompat.widget.LinearLayoutCompat>
        </ScrollView>
    </TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

custom_styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="small_font">
    <item name="android:textColor">@color/black</item>
    <item name="android:textSize">12sp</item>
    <item name="android:textStyle">normal</item>
</style>

<style name="small_font_italic">
    <item name="android:textSize">12sp</item>
    <item name="android:textStyle">italic</item>
</style>

<style name="radioButtonStyle">
    <item name="android:layout_width">75dp</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:textColor">@color/black</item>
    <item name="android:textSize">12sp</item>
    <item name="android:button">null</item>
    <item name="android:gravity">center</item>
    <item name="android:onClick">radioTapped</item>
</style>

<style name="reward_style">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">12sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:background">@drawable/tracker_gradient</item>
</style>
</resources>

values.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="default_web_client_id" translatable="false">-</string>
    <string name="firebase_database_url" translatable="false">-</string>
    <string name="gcm_defaultSenderId" translatable="false">-</string>
    <string name="google_api_key" translatable="false">-</string>
    <string name="google_app_id" translatable="false">-</string>
    <string name="google_crash_reporting_api_key" translatable="false">-</string>
    <string name="google_storage_bucket" translatable="false">-</string>
    <string name="project_id" translatable="false">-</string>
</resources>

I replace my values within values.xml with dashes.

Ran out of space for other 2 xml, open to suggestion how to fit into the question.

CodePudding user response:

I would suggest to make sure that whatever is in your values.xml is well formatted. Last time I encountered a similiar error I had a color resource without the starting # so perhaps you could look into that

CodePudding user response:

Update: my friend who generated the error manage to resolve the issue, hopefully it won't arise again.

The changes: app/build.gradle

implmentation {
implementation 'com.jjoe64:graphview:4.2.2'
}

somehow it relates to gradle instead.

  • Related