2017-01-01 38 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旁边的设置也可以。