WARNING: API 'variant.getMergeAssets()' is obsolete / Android Studio 3.3
Asked Answered
I

1

14

After the recent android update, each time I build my app, I receive the following warnings:

WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'. 
API 'variant.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'. 
API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.

While I did search the web for solutions but most recommended ignoring the problem and waiting for future updates that would have the fix. There were other solutions presented as well but those didn't work at all. As a result, I ran my app ignoring the warnings.

When the app loaded in my virtual device, the TextInput nor the Button respond to the touch making them useless. I am using react native for the app. Please help me solve the issue as it didn't occur before the gradle warnings.

My build.gradle(Module:app) has the following lines:

apply plugin: 'com.android.application'

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "com.multiapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.configureEach { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation project(':react-native-video')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-sqlite-storage')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:28.0.0"
    implementation "com.facebook.react:react-native:0.57.8"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}
Illinois answered 29/1, 2019 at 11:29 Comment(12)
Possible duplicate of variantOutput.getPackageApplication() is obsoleteBeulabeulah
only getPackageApplication() could be fixed. the other two warnings most likely come from a plugin which is being referenced in apply from: "...react.gradle". just wait from them to update it. there is nothing to do about it, unless downgrading to Gradle plugin 3.2.1.Beulabeulah
@MartinZeitler I tried downgrading but that didn't help.Illinois
just clean the project once. you could file a bug against: github.com/facebook/react-native/blob/master/react.gradle ...which might use the obsolete API.Beulabeulah
1) It's just a warning. 2) If you don't call it, one of the plugins calls it (fabric, react, whoever). 3) You're not losing any performance. It just means they're using the same API that was available until now. They're not yet using the new lazy configuration API which may be more efficient. 4) Check out https://mcmap.net/q/129441/-while-android-studio-updated-to-v3-3-getting-api-39-variant-getassemble-39-is-obsolete-and-has-been-replaced-with-39-variant-getassembleprovider-39, I've been over this once before.Dalmatian
@MartinZeitler I did as you told. First cleaned my project through Build > Clean Project. After that opened my react.gradle file and updated the code from github.com/facebook/react-native/blob/master/react.gradle as they have updated the obsolete API. But the compiler still shows the same problems.Illinois
Of course, if something broke as you say, it's probably because the version of React plugin you're using is not compatible with your Android Gradle plugin version.Dalmatian
@EugenPechanec I was ignoring the issues but I can't use <TextInput>, <Button> or any components that change the screen layout. Since I never had any issue before the update, I am pretty sure the obsolete API is causing it.Illinois
when changing a build.gradle and nothing changes ...caching is to blame. can only confirm what @EugenPechanec wrote, that an obsolete warning is neither an error, nor does it change the behavior - it is merely meant as a reminder for plugin providers, to update their code.Beulabeulah
@MartinZeitler Hey it got fixed. I was updating a different project and loading a different one. Thanks! I will put the answer below.Illinois
@EugenPechanec Hey found the answer. Thanks anyways.Illinois
@MartinZeitler would be a great help if you upvote the question so future new react native users can solve the issue. :)Illinois
I
16

Source: @MartinZeitler

Steps to fix the obsolete API if you're using React Native like me.

  1. Locate the react.gradle file. (ProjectName/node_modules/react-native/react.gradle)

  2. Open the file in your favorite text editor.

  3. Update the code from https://github.com/facebook/react-native/blob/master/react.gradle

  4. Click on Build

Hoping it gets automatically updated.

Illinois answered 2/2, 2019 at 16:13 Comment(6)
experiencing this with react-native 0.57.8 and I think that I should update github.com/facebook/react-native/releases?after=v0.58.3Mucous
I am using react-native 0.58.6 but still, have the issues. So, I just change the react.gradle file each time I create a new project.Illinois
Build where? It doesn't get detected as a file change in the Android Studio as this react.gradle file is externally located.Capers
@Capers If so, click on "Build" in the menu. After you hit the Build a list will appear. Just click on "Rebuild Project".Illinois
any solution if using FlutterDhar
@Dhar I am sorry. I don't use flutter at all so I can't help you.Illinois

© 2022 - 2024 — McMap. All rights reserved.