Changing Android application ID leads to linking issue

  android, applicationid, attributes, linker

Android 4.1.1
compiledSdkVersion 30
targetSdkVersion 30
minSdkVersion 24

Gradle: 6.5
Android Gradle Plugin: 4.1.1

Changing application id in build.gradle leads to attribute not found error during linking

        applicationId "com.myltd.asg.myappid"

I tried changing the package name to the same value just for testing but it does not remove the error.
I know that according to the manual, it should be possible to have different values for package name and application id.
https://developer.android.com/studio/build/application-id.html

The linking issue is

C:devsourcemyAppappsrcmainreslayoutmyactivity.xml:23: AAPT: error: attribute com.myltd.asg.myappid:settingsKey not found.
    
C:devsourcemyAppappsrcmainreslayoutmyactivity.xml:23: AAPT: error: attribute com.myltd.asg.myappid:textSize not found.
    
C:devsourcemyAppappsrcmainreslayoutmyactivity.xml:23: AAPT: error: attribute com.myltd.asg.myappid:titleText not found.
    
C:devsourcemyAppappsrcmainreslayoutmyactivity.xml:23: AAPT: error: attribute com.myltd.asg.myappid:voiceText not found.
    
C:devsourcemyAppappsrcmainreslayoutmyactivity.xml:23: AAPT: error: attribute com.myltd.asg.myappid:hideEmpty not found.

This is myactivity.xml:

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/nav_drawer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="@dimen/nav_drawer_elevation">

    <ScrollView
        android:id="@+id/rootScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background"
        android:fillViewport="true">

        <LinearLayout
            android:id="@+id/layout_main"
            xmlns:custom="http://schemas.android.com/apk/res/com.myltd.asg.myappid"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="8sp">

            <com.myltd.asg.myappid.ui.utils.RelativeLayoutExpand
                android:id="@+id/ziadaValueJagha"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                custom:sgKey="@string/key_checkbox_preference_zs"
                custom:hide="true"
                custom:textSize="@dimen/biggerTextSize"
                custom:titleText="@string/za"
                custom:commentText="@string/za_awaz"/>

            <com.myltd.asg.myappid.ui.utils.RelativeLayoutExpand  <!----- here is the error reported for the attributes used in this element! --!>
                android:id="@+id/aamAddress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                custom:hide="true"
                custom:sgKey="@string/key_checkbox_preference_log"
                custom:textSize="@dimen/biggerTextSize"
                custom:titleText="@string/logical_Jagha"
                custom:commentText="@string/logical_Jagha_awaz"/>

            <LinearLayout
                style="@style/list_row_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <CheckBox
                    android:id="@+id/detailS"
                    style="@style/details_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:checked="false"
                    android:enabled="true" />

                <TextView
                    style="@style/details_value"
                    android:layout_width="0sp"
                    android:layout_height="wrap_content"

                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:gravity="start"
                    android:text="@string/detail_title"/>

            </LinearLayout>


        </LinearLayout>

    </ScrollView>
    <include
        layout="@layout/nav_drawer">
    </include>
</androidx.drawerlayout.widget.DrawerLayout>

The aatributes are defined in this java file which expands the RelativeLayout. The variables are initialized in constructors of the class.

public class RelativeLayoutExpand extends RelativeLayout {

    private TextViewMeasure leftTextView;
    private TextViewMeasure rightTextView;
    private LayoutParams paramsRight;
    private String titleText = null;
    private String commentText= null;
    private String sgKey = null;
    private boolean hide = false;
    private int textSize;
...
}

The linking issue just appears with this specific file. If I create a simple project without anything fancy than this, there is no issue when application id or package name are changed.

Note: This code is extracted from an existing legacy app which we have to maintain. Removing RelativeLayoutExpand and just using standard linearLayout is an option but the code change in the app requires big effort as the attributes are used in main part of the app and cannot be easily refactored outside this java class.

I am hoping to get some idea how this linking error can be removed without big refactoring effort in the app.

Any pointer to documentation or hint to some Java/Android detail is much appreciated.

Already tried:

  • clean project and rebuild
  • invalidate and restart Android Studio
  • and ofcourse also changed package name to match application id (just to be safe)

Source: Android Questions

LEAVE A COMMENT