javafxports multidex minSdkVersion is set to 20 or less

336 Views Asked by At

Researched the cause identified in this issue Link to initial cause of issue. The solution is to implement the required use of the android multidex library on android sdk versions 20 or less.

The issue now is how to implement the solution detailed at this link Using multidex when minSdkVersion is set to 20 or lower

Extract from link.

If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:

public class MyApplication extends MultiDexApplication { ... }

Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(context);
     Multidex.install(this);
  }
}

The full package names for the classes mentioned in the above code are

android.support.multidex.MultiDexApplication
android.app.Application

The javafx application extends javafx.application.Application

The question is - how to implemented the multidex solution when extending javafx.application.Application when using javafxports?

Now including the AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ie.murphysoftware.games.magnatron"
    android:versionCode="5"
    android:versionName="5.0">
    <supports-screens android:xlargeScreens="true" />
    <uses-sdk android:minSdkVersion="21"/>
    <application android:icon="@drawable/magnatron_icon" android:label="@string/app_name">
        <activity android:name="javafxports.android.FXActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <meta-data android:name="launcher.class" android:value="javafxports.android.DalvikLauncher" />
            <!-- Full name of the application class to run -->
            <meta-data android:name="main.class"
                android:value="ie.murphysoftware.games.magnatron.MagnatronStart" />
            <!-- Jvm arguments (delimiter |) -->
            <meta-data android:name="jvm.args"
                android:value="-Djavafx.verbose=true|-Djavafx.name=value" />
            <!--This meta-data tag is required to use Google Play Services.-->
            <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
            <!-- Application arguments (delimiter |) -->
            <meta-data android:name="app.args" android:value="arg1|arg2" />
            <!-- Jdwp debugging port. Don't forget to forward port (adb forward tcp:port1 tcp:port2) -->
            <meta-data android:name="debug.port" android:value="0" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    </application>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="com.android.vending.BILLING"></uses-permission>
</manifest>
1

There are 1 best solutions below

0
On

Please have a look on an example project, I needed to create in Order to solve an issue with the UI rendering. Initially it was really slow and took up to 7s (2s FXML parsing, approx. 5s frozen UI) on my Nexus 6 and is now down to approx. 2.5s.

Here's the Manifest:

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="eu.dzim.example" android:versionCode="1" android:versionName="1.0">
    <supports-screens android:xlargeScreens="true"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="21"/>
    <application android:label="ExampleProject" android:name="android.support.multidex.MultiDexApplication" android:icon="@mipmap/ic_launcher">
            <activity android:name="javafxports.android.FXActivity" android:label="ExampleProject" android:configChanges="orientation|screenSize">
                    <meta-data android:name="main.class" android:value="eu.dzim.example.Main"/>
                    <meta-data android:name="debug.port" android:value="0"/>
                    <intent-filter>
                            <action android:name="android.intent.action.MAIN"/>
                            <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
            </activity>
    </application>
</manifest>

Note: android:name="android.support.multidex.MultiDexApplication" on the <application> tag.

The Gradle file looks like:

buildscript {
    repositories {
    jcenter()
    }
    dependencies {
    classpath 'org.javafxports:jfxmobile-plugin:1.2.0'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
    url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'eu.dzim.example.Main'

dependencies {

    compile 'com.gluonhq:charm:4.2.0'

    compile 'org.controlsfx:controlsfx:8.40.12'
    compile 'de.jensd:fontawesomefx-commons:8.13'
    compile 'de.jensd:fontawesomefx-fontawesome:4.7.0'
    compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22'

    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.4'

    compileNoRetrolambda 'com.airhacks:afterburner.mfx:1.6.2'
}

jfxmobile {
    downConfig {
    version = '3.1.0'
    plugins 'display', 'lifecycle', 'statusbar', 'storage', 'settings'
    }
    android {
    manifest = 'src/android/AndroidManifest.xml'
    compileSdkVersion = 22
    minSdkVersion = 19
    targetSdkVersion = 22
    dexOptions {
        javaMaxHeapSize '2g'
    }
    packagingOptions {
        pickFirst 'META-INF/LICENSE'
        pickFirst 'META-INF/NOTICE'
        pickFirst 'license/LICENSE.txt'
    }
    }
}

I created the Android/Desktop set-up with the IDE plugin for Eclipse (but this should not matter).

I just-rechecked it, build it and verified, that there were two dex files in build/javafxports/tmp/android/dex:

  • classes.dex
  • classes2.dex

I triggered the build via the task androidInstall and the app run as expected on a Nexus 5 test device.

So please: Compare those files with your set-up. Try to build and install it. As I said: It works fine for me...


Additionally I read on some other post here on StackOverflow, that one solved a dex-issue by simply using the correct JDK (64bit instead of 32bit). So make sure, your set-up beside the Gradle and Manifest is ok as well.