10

Well, I started a migration to AndroidX from a year old project (untouched since then) and I have problems withs the resources and the gradle build. Im completely lost with the new namespaces, I changed some of them, I upgraded all the things AndroidStudio told me, but still not recognizing things on my project. I will paste both gradle here and Ill put the error below.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Module

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.example.usuario.tm"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test:runner:1.1.0-alpha3"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha3', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        implementation 'androidx.appcompat:appcompat:1.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        implementation 'com.google.android.material:material:1.0.0'
        implementation 'com.google.gms:google-services:4.1.0'
        implementation 'com.google.android.gms:play-services-auth:16.0.1'
        testImplementation 'junit:junit:4.12'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'maven'

Error

Android resource linking failed
Output:  C:\Users\Xrless\Desktop\Programing\TN\TM\app\src\main\res\layout\activity_principal.xml:34: error: attribute android:style not found.
error: failed linking file resources.

Command: C:\Users\Xrless\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\cf456f090f0725907522fb6d2bec3322\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
        C:\Users\Xrless\AppData\Local\Android\Sdk\platforms\android-28\android.jar\
        --manifest\
        C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
        -o\
        C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
        -R\
        @C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
        --auto-add-overlay\
        --java\
        C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
        --custom-package\
        com.example.usuario.tm\
        -0\
        apk\
        --output-text-symbols\
        C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\symbols\debug\R.txt\
        --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
Zoe
  • 27,060
  • 21
  • 118
  • 148
Santiago Bozzi
  • 139
  • 1
  • 1
  • 10

7 Answers7

3

There is an error in your activity_principal.xml. Try to change:

android:style

to

style

Also you need to add

android.useAndroidX=true

to your gradle.properties file if you want to use androidX library instead of Support Library.

Sinan Ceylan
  • 1,043
  • 1
  • 10
  • 14
  • 1
    I have written a full article on the topic, especially the manual fixes, hopefully, it will elaborate further https://handyopinion.com/ultimate-guide-to-migrate-android-project-to-androidx/ – Asad Ali Choudhry Oct 31 '19 at 08:34
1

In AndroidStudio 3.2+ you can use Refactor | Migrate to AndroidX to upgrade a project. For more go here.

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
werfar
  • 121
  • 1
  • 5
1

I spent an entire night trying to solve this issue after the migration to androidX. Below are the few things I did for it to work:

In gradle.property:

dex.force.jumbo=true
android.useAndroidX=true
android.enableJetifier=true
android.enableD8=true
android.enableR8.libraries = false
android.enableR8 = false

In build.gradle:

defaultConfig {
    ...
    compileSdkVersion 28
    …
}
//Use JDK1.8 and make sure the same is well specified in your gradle file.
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
//Exclude Guava libraries
 ...
configurations {
    ...
    implementation.exclude group: 'com.google.guava'
}

//Make sure your firebase and google libraries are all updated
   ...
   implementation 'com.google.guava:guava:27.0.1-android'
   ...

After all these, few usual things:

  • Make sure you update your gradle to the latest version (3.4.2 as of now)
  • the previous action will require android Studio version 3.4 and above
  • Clear your Gradle caches(use this command if on macOs rm -rf $HOME/.gradle/caches/)
  • Invalidate caches and restart, ...
  • The rest will be just to change few implementations that were not refactored properly.

Think all should be find after that. Hope it saves you some time.

Kamal
  • 44
  • 6
Gomez NL
  • 912
  • 9
  • 12
0
  1. implementation androidx.appcompat:appcompat:1.0.0-alpha1
  2. implementation androidx.constraintlayout:constraintlayout:1.1.2
initialise
  • 211
  • 1
  • 3
  • 11
0

Nice, I changed both implementations and added the androix=true to the property file. The build gradle thing is not throwing errors anymore (I think) But my layouts are not visible on the design view

IMAGE OF THE PROBLEM

enter image description here

And this:

IMAGE OF THE PROBLEM 2

enter image description here

punchman
  • 1,350
  • 1
  • 13
  • 23
Santiago Bozzi
  • 139
  • 1
  • 1
  • 10
  • You have to manually update the layout references. The widgets will be referencing the old support library. You have to update all the references in each layout – portfoliobuilder Sep 16 '19 at 21:25
0

open gralde.properties file add below line

android.useAndroidX = true

Sync project

It works perfectly.

sssvrock
  • 549
  • 7
  • 8
0

Although the accepted answer is correct. But to help other guys, In complex projects, we found such kind of many errors which we need to fix manually. I have written a full article on the topic, especially the manual fixes. Ultimate Guide to Migrate Android Project to AndroidX.

Asad Ali Choudhry
  • 4,985
  • 4
  • 31
  • 36