Search code examples
migrationandroid-support-libraryandroidx

AndroidX FrameLayout layout_heightPercent attribute not found error


Tried upgrading my Android Project from API 25 to AndroidX , I am using the following in the Layout

<FrameLayout
        android:id="@+id/frame0"
        app:layout_heightPercent="10%"
        android:layout_marginTop="50dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adViewFirstPage1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_1"
        android:layout_gravity="center"
        />

This is the upgraded gradle file for AndroidX - taken from GitHub Google Samples

 implementation 'androidx.appcompat:appcompat:1.1.0'
 implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'com.google.firebase:firebase-iid:20.0.2'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'android.arch.work:work-runtime:1.0.1'

Now I getting errors like layout_heightPercent not found error in FrameLayout AAPT: error: attribute adUnitId not found in AdMob Banner

As per Documentation I couldn't find the proper library. A little help would be highly useful.


Solution

  • The following is the app gradle file content

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 30
        defaultConfig {
            applicationId "com.myproject"
            minSdkVersion 16
            targetSdkVersion 30
            versionCode 5
            versionName "1.0"
            testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
            multiDexEnabled true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        android {
            useLibrary 'org.apache.http.legacy'
        }
    }
    repositories {
        maven { url "https://jitpack.io" }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
        androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
    
        implementation 'com.android.support:multidex:1.0.3'
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'com.google.android.material:material:1.1.0'
        implementation 'androidx.percentlayout:percentlayout:1.0.0'
        implementation 'com.github.PhilJay:MPAndroidChart:v2.1.6'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    
        implementation 'com.google.android.gms:play-services-ads:19.2.0'
        implementation 'com.google.firebase:firebase-iid:20.2.3'
        implementation 'com.google.firebase:firebase-messaging:20.2.3'
        // For an optimal experience using FCM, add the Firebase SDK
        // for Google Analytics. This is recommended, but not required.
        implementation 'com.google.firebase:firebase-analytics:17.4.4'
    
        implementation 'com.google.code.gson:gson:2.8.5'
        implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
        implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
        implementation 'com.squareup.okhttp3:okhttp:3.10.0'
        testImplementation 'junit:junit:4.12'
    }
    
    apply plugin: 'com.google.gms.google-services'
    

    The following is the project gradle

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
            jcenter()
            google()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:4.0.0'
            classpath 'com.google.gms:google-services:4.3.3'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
            google()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    After updating this we need to refactor the project. Sometime we need to change the import statements in the project accordingly.