2017-01-01 37 views
0

研究了此問題中確定的原因Link to initial cause of issue。解決方案是在android sdk版本20或更低版本上實現所需的android multidex庫。javafxports multidex minSdkVersion設置爲20或更少

現在的問題是如何實現這個鏈接Using multidex when minSdkVersion is set to 20 or lower

從鏈接提取詳細的解決方案。

如果你重寫應用程序類,將其更改爲延長 MultiDexApplication(如果可能)如下:

public class MyApplication extends MultiDexApplication { ... } 

或者如果你重寫應用程序類,但它不可能 變化基礎類,那麼你就可以代替覆蓋 attachBaseContext()方法,並調用MultiDex.install(本),以使 multidex:

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

用於上述代碼提到的類的完整的包名稱是

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

JavaFX應用程序延伸javafx.application.Application

問題是 - 如何使用javafxports時延伸javafx.application.Application時實現的multidex溶液?

現在包括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> 
+0

AFAIK您在現實生活場景中不需要顯式MultiDexApplication(經常)。通常可以在Android上啓用多重分錄。再說一次:據我所知,這已經是javafxports插件默認的activer了。你能否詳細說明,爲什麼你需要擴展MultiDexApplication?順便說一下:如果你想使用另一個默認的Android'Application',你必須在Android Manifest中指定:https://developer.android.com/guide/topics/manifest/application-element.html# nm(屬性「名稱」)。 – dzim

+0

@dzim在此鏈接https://developer.android.com/studio/build/multidex.html上查看標題爲「Android 5.0之前的Multidex支持」的部分。請注意,我在我的問題中包含了此鏈接。 –

+0

好的,我得到__this__部分(我確實沒有閱讀過Android Dev頁面)。但是,當你有一個JavaFX'Application'類時,你會問,如何使用Android'MultiDexApplication'類。答案是:沒問題,完全分開。創建一個'MultiDexApplication'類並將其設置到Android Manifest中。它們是完全不同的東西,你不需要爲JavaFX應用程序做些什麼。只需要Android特定的應用程序。你可以試試嗎?還是應該用我建議的解決方案發布答案​​(它希望是:-D)? – dzim

回答

0

請有實例項目一看,我需要爲了解決一個問題,與UI渲染創建。最初它非常慢,在我的Nexus 6上花費了7s(2s FXML解析,大約5s凍結的UI),現在已經降到了大約。 2.5秒。

這裏的清單:

<?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> 

注:<application>標籤android:name="android.support.multidex.MultiDexApplication"

的搖籃文件看起來像:

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' 
    } 
    } 
} 

我創建了Android /桌面設置了Eclipse的IDE插件(但是這不應該的問題)。

我剛剛檢查完畢,建立並覈實,認爲有在build/javafxports/tmp/android/dex 2個DEX文件:

  • classes.dex
  • classes2.dex

我通過觸發構建任務androidInstall和應用程序按預期在Nexus 5測試設備上運行。

所以請:比較這些文件與您的設置。嘗試構建並安裝它。正如我所說的:它工作正常,我...


此外,我在這裏StackOverflow上一些其他職位閱讀,一個只需要使用正確的JDK(64位而不是32位)解決的DEX-問題。所以請確保,您的Gradle和Manifest旁邊的設置也可以。