Android 安装正在错误的位置查找类



为了解决更大的问题,我创建了一个示例应用程序,我可以测试问题所在。该代码与单视图向导生成的代码基本相同。

当我通过appliaction > run在桌面上启动它时,它工作正常。当我通过other > androidInstall从我的设备运行它时,我得到一个黑屏(我也事先运行了clean)。所以我启动了adb logcat并发现了这个错误:

E DalvikLauncher: java.lang.ClassNotFoundException: Not find class 路径上的"com.gluonapplication.GluonApplication":DexPathList[[zip file "/data/app/com.gluonapplication-1/base.apk"],nativeLibraryDirectory=[/data/app/com.gluonapplication-1/lib/arm,/data/app/com.gluonapplication-1/base.apk!/lib/armeabi,/vendor/lib,/system/lib]]

这并不奇怪,因为那里没有阶级。主类位于main.GluonApplication(包名称可能不正确,但它是测试应用程序)。build.gradle具体规定了mainClassName = 'main.GluonApplication'.那么,为什么Android版本在其他地方寻找呢?是否有我需要编辑/重新创建的清单?是否有某种缓存在以前版本的应用程序可能驻留并影响当前版本的某个地方完成?

每当使用 IDE 插件创建项目时,都会有一个默认清单AndroidManifest.xml添加到src/android/文件夹中。

如果打开它,您会发现分配的包名称,它将与主类的包及其全名匹配。

根据您在日志上找到的内容,这将是您当前的清单:

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.gluonapplication" 
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="GluonApplication" android:name="android.support.multidex.MultiDexApplication" android:icon="@mipmap/ic_launcher">
<activity android:name="javafxports.android.FXActivity" android:label="GoNative" android:configChanges="orientation|screenSize">
<meta-data android:name="main.class" android:value="com.gluonapplication.GluonApplication"/>
<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>

只需确保包名称与真实名称匹配,否则进行必要的更改。

另请注意,在 Android 上,您至少需要两个单词和一个点作为有效的软件包名称,例如com.gluonapplication

最新更新