Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration to AndroidX

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
like image 444
Santiago Bozzi Avatar asked Oct 24 '18 03:10

Santiago Bozzi


3 Answers

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.

like image 194
Sinan Ceylan Avatar answered Oct 16 '22 11:10

Sinan Ceylan


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

like image 30
werfar Avatar answered Oct 16 '22 12:10

werfar


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.

like image 1
Gomez NL Avatar answered Oct 16 '22 12:10

Gomez NL