Search code examples
javaandroidgradlematerial-uimaterial-components-android

android studio - fail to build project after Material dependency upgrade


The requirement is to upgrade all gradle dependencies of an old android app. Managed to upgrade all to latest and is able to build and run the app. When I upgraded the Material dependency from com.google.android.material:material:1.1.0 to the latest com.google.android.material:material:1.11.0 I got the following error:

Illegal char <:> at index 56: app.com.my.app-mergeMyAppDebugResources-50:/values/values.xml

Execution failed for task ':app:mergeMyAppDebugResources'.

A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable Resource compilation failed (Failed to compile values resource file S:\Work\android\app\app_newImpl2023-12-27\app.com.my.app.android\myapp\app\build\intermediates\incremental\MyAppDebug\mergeMyAppDebugResources\merged.dir\values\values.xml. Cause: java.nio.file.InvalidPathException: Illegal char <:> at index 56: app.com.my.app-mergeMyAppDebugResources-50:/values/values.xml). Check logs for more details

I have looked into most if not all SO questions that are related to build error - illegal char. But non solved my problem. Which only appears when Material is upgraded.

Build gradle (:app) dependencies:

dependencies {
    implementation fileTree(include: '*.jar', dir: 'libs')
    implementation 'com.google.android.gms:play-services-auth:20.7.0'
    // Required for local unit tests (JUnit 4 framework)
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.13.0'
    testImplementation 'org.powermock:powermock-core:1.7.3'
    testImplementation 'org.powermock:powermock-module-junit4:1.7.3'
    testImplementation 'org.powermock:powermock-api-mockito2:1.7.3'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    // Required for instrumented tests
    androidTestImplementation 'androidx.annotation:annotation:1.7.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'com.sothree.slidinguppanel:library:3.4.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'
    //picasso
    implementation 'com.squareup.picasso:picasso:2.71828'
    //retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    implementation 'ru.noties:debug:2.0.2'
    implementation 'com.github.castorflex.verticalviewpager:library:19.0.1'
    implementation 'com.andrognito.pinlockview:pinlockview:1.0.1'
    implementation 'me.dm7.barcodescanner:zxing:1.9.13'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
    implementation 'org.apache.commons:commons-lang3:3.7'
    implementation 'com.flipkart.springyheads:library:0.9.6'
    implementation 'jp.wasabeef:blurry:2.1.1'
    implementation 'com.google.firebase:firebase-core:21.1.1'
    implementation 'com.google.firebase:firebase-messaging:23.4.0'
    implementation 'com.google.firebase:firebase-config:21.6.0'
    implementation 'com.github.bumptech.glide:glide:4.4.0'
    implementation 'com.github.HITGIF:TextFieldBoxes:1.4.4'
    implementation 'com.google.code.gson:gson:2.9.0'
    //retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    //social media login
    implementation 'com.facebook.android:facebook-login:latest.release'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    implementation 'com.squareup.okhttp3:okhttp:4.9.3'
} 
apply plugin: 'com.google.gms.google-services'

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

What I have tried:

1- Invalidate cache.

2- Looked into Strings file for illegal <:>. found couple of strings that has :, removed all of them to try to build the project, still didn't work.

3- colors file doesn't have any : character.

4- styles file has something like <item name="android:buttonStyle">? android:attr/borderlessButtonStyle</item> Which I commented to try to build, but again same error.

5- In merged values file the char <:> is repeated more than 2000 times which makes it very difficult to check where the problem is.

6- there's no attr file under values folder

My questions:
1-What causes merged values file error when upgrading the material dependency?

2- Where should I start to try and debug this problem other than what I have tried already.

Thank you


Solution

  • Answering my own question..

    What I did to try and get more info about this error is:

    1. Install android studio on mac book (Android Studio Hedgehog | 2023.1.1 Patch 1).
    2. run the app to make sure all is good before upgrading material dependency.
    3. Upgrade Material to latest com.google.android.material:material:1.11.0
    4. Build the project. I got more detailed error including the line inside the values file.
    5. The error shows a duplicate declaration of TextInputEditText. I searched inside the file and found this is declared in both Material and another dependency com.github.HITGIF:TextFieldBoxes:1.4.4
    6. Commented this dependency in gradle file, sync then was able to successfully build the project.

    Thanks