Search code examples
androidcordovaibm-mobilefirstproguardcordova-plugin-proguard

Proguard warnings when doing android release build with MobileFirst 8.0 IF201804051553


I recently upgraded my hybrid MobileFirst app's mfp plugins to 8.0.20180408, and my cordova-android plugin to 7.0.0. When I did a debug build of the app, the build succeeded, but the moment I did a release build (signed apk) the process generated a lot of proguard warnings. When I downgraded the cordova-android version to 6.4.0 the release build succeeded.

The mobilefirst cordova plugin is supposed to support cordova-android v7 Since the MobileFirst iFix 8.0.0.0-MFPF-IF201804051553, as per the iFix release notes, but it seems that there is a problem with the it in this ifix.


Solution

  • I did some investigation into the proguard configuration file as there seem to be a problem with the gradle build process finding the right proguard configuration file.

    The mfp cordova plugin contains a proguard configuration file called proguard-project-mfp.txt, which is added to the android platform of the hybrid project. The plugin also contains a gradle file

    dev-build-extras.gradle

    which specifies the location of the proguard configuration file. The proguard file specified in the configuration has no path attached to it:

    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-mfp.txt'

    It seems that in cordova-android 7.x, when the android platform is generated, it copies the proguard-project-mfp.txt file to the directory

    platforms/android/app/src/main/
    whereas the dev-build-extras.gradle file is located in the directory
    platforms/android/cordova-plugin-mfp/

    This means that gradle cannot find the proguard configuration file. Updating the proguard configuration file location in the gradle file relative to the gradle file seems to solve the problem and allows for the signed apk to be built.

    In summary, update the file

    platforms/android/cordova-plugin-mfp/dev-build-extras.gradle

    with the following

    // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-mfp.txt'
    proguardFiles getDefaultProguardFile('proguard-android.txt'), '../app/src/main/proguard-project-mfp.txt'

    Your dev-build-extras.gradle file should now look like this:

    android {
        buildTypes {
            release {
                minifyEnabled true
                // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-mfp.txt'
                proguardFiles getDefaultProguardFile('proguard-android.txt'), '../app/src/main/proguard-project-mfp.txt'
            }
        }
        .
        .
        .
    }