我正在关注http://developer.android.com/guide/market/expansion-files.html上的开发指南,以便将其他资产下载到我的 apk。
我已经完成了关于库的导入等的所有部分。我还在我的主程序中实现了示例代码(为了检测扩展文件是否已经下载,如果我们需要下载它们并启动下载, ETC ..)
我在 eclipse 中没有错误,但是当我启动应用程序并开始从库中调用方法和类时,我遇到了各种崩溃:
1 - 首先,在安装时,adb 说找不到库..:
[2012-04-17 22:50:13 - MyApp] adb is running normally.
[2012-04-17 22:50:13 - MyApp] Performing com.gmla.MyApp activity launch
[2012-04-17 22:50:16 - MyApp] Uploading MyApp.apk onto device 'SH16PV801048'
[2012-04-17 22:50:16 - MyApp] Installing MyApp.apk...
[2012-04-17 22:50:22 - MyApp] Success!
[2012-04-17 22:50:22 - Google Play Downloader Library] Could not find Google Play Downloader Library.apk!
[2012-04-17 22:50:22 - Google Play License Library] Could not find Google Play License Library.apk!
这是我如何尝试导入我的库的屏幕截图:http: //floy.fr/perso/floy/expfiles/4.PNG
我已经在我的主要项目属性中的 Java 构建路径中导入了带有项目导入的库,如a)部分:(也以这种方式在下载库中导入了许可证库)
我还尝试只导入b)部分中的 jars (安装时没有错误)
并使用c部分中的 Android 库导入) (这似乎是开发指南中推荐的一种,但我对此有编译错误,eclipse 找不到一些参考资料,我无法构建项目):
因此,jar 导入似乎是最好的,编译和安装时没有错误,但是当我从库中调用方法和类时,我遇到了其他错误:
2 - 在应用程序中:
当我尝试使用帮助程序以使用此方法检查 XAPKFiles 的存在时:
boolean expansionFilesDelivered() {
XAPKFile[] xAPKS = {new XAPKFile(true, 3, 687801613L)
// main file only
};
for (XAPKFile xf : xAPKS) {
String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false))
return false;
}
return true;
}
我在 DDMS 中有这个崩溃:
04-17 23:14:24.614: I/dalvikvm(23201): Could not find method com.google.android.vending.expansion.downloader.Helpers.getExpansionAPKFileName, referenced from method com.gmla.guideaudio.apkexp.GmlaCheckExpFiles.expansionFilesDelivered
04-17 23:14:24.614: W/dalvikvm(23201): VFY: unable to resolve static method 1295: Lcom/google/android/vending/expansion/downloader/Helpers;.getExpansionAPKFileName (Landroid/content/Context;ZI)Ljava/lang/String;
04-17 23:14:24.614: D/dalvikvm(23201): VFY: replacing opcode 0x71 at 0x001b
04-17 23:14:24.614: W/dalvikvm(23201): Unable to resolve superclass of Lcom/gmla/guideaudio/apkexp/GmlaDownloaderService; (250)
04-17 23:14:24.614: W/dalvikvm(23201): Link of class 'Lcom/gmla/guideaudio/apkexp/GmlaDownloaderService;' failed
04-17 23:14:24.614: E/dalvikvm(23201): Could not find class 'com.gmla.guideaudio.apkexp.GmlaDownloaderService', referenced from method com.gmla.guideaudio.apkexp.GmlaCheckExpFiles.onCreate
04-17 23:14:24.614: W/dalvikvm(23201): VFY: unable to resolve const-class 135 (Lcom/gmla/guideaudio/apkexp/GmlaDownloaderService;) in Lcom/gmla/guideaudio/apkexp/GmlaCheckExpFiles;
04-17 23:14:24.614: D/dalvikvm(23201): VFY: replacing opcode 0x1c at 0x001c
04-17 23:14:24.624: V/Performance(23201): >>com.gmla.guideaudio.apkexp.GmlaCheckExpFiles@40db32b0 onCreate
04-17 23:14:24.624: D/AndroidRuntime(23201): Shutting down VM
04-17 23:14:24.624: W/dalvikvm(23201): threadid=1: thread exiting with uncaught exception (group=0x40abf228)
04-17 23:14:24.624: E/AndroidRuntime(23201): FATAL EXCEPTION: main
04-17 23:14:24.624: E/AndroidRuntime(23201): java.lang.NoClassDefFoundError: com.google.android.vending.expansion.downloader.Helpers
04-17 23:14:24.624: E/AndroidRuntime(23201): at com.gmla.guideaudio.apkexp.GmlaCheckExpFiles.expansionFilesDelivered(GmlaCheckExpFiles.java:64)
04-17 23:14:24.624: E/AndroidRuntime(23201): at com.gmla.guideaudio.apkexp.GmlaCheckExpFiles.onCreate(GmlaCheckExpFiles.java:22)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.app.Activity.performCreate(Activity.java:4524)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2189)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.app.ActivityThread.access$600(ActivityThread.java:139)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.os.Looper.loop(Looper.java:154)
04-17 23:14:24.624: E/AndroidRuntime(23201): at android.app.ActivityThread.main(ActivityThread.java:4894)
04-17 23:14:24.624: E/AndroidRuntime(23201): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 23:14:24.624: E/AndroidRuntime(23201): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 23:14:24.624: E/AndroidRuntime(23201): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 23:14:24.624: E/AndroidRuntime(23201): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 23:14:24.624: E/AndroidRuntime(23201): at dalvik.system.NativeStart.main(Native Method)
当我在导入库时使用方法 1 或 2 时会发生此崩溃。
我试图将 ant 更新到最新的 1.8.3,因为我读到 1.7.1 可能在库导入方面存在一些问题.. 解决我的问题没有成功。
我的主要应用程序在 Google API 8 (Android 2.2) 上
为了使它起作用,我搜索了很多东西,但是..现在我完全没有主意了!
如果有人知道如何让这个工作,那将是非常友好的:p
对不起这篇长篇文章,对不起我的英语,如果我拼写错误,那是因为我是法国人:p
编辑:我已经尝试了下载器示例代码,使用库导入方法c),这次我没有编译错误,但是在安装过程中:
[2012-04-18 01:56:16 - GuideAudio] Android Launch!
[2012-04-18 01:56:16 - GuideAudio] adb is running normally.
[2012-04-18 01:56:16 - GuideAudio] Performing com.gmla.guideaudio.GuideAudio activity launch
[2012-04-18 01:56:19 - GuideAudio] Uploading GuideAudio.apk onto device 'SH16PV801048'
[2012-04-18 01:56:19 - GuideAudio] Installing GuideAudio.apk...
[2012-04-18 01:56:21 - GuideAudio] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2012-04-18 01:56:21 - GuideAudio] Please check logcat output for more details.
[2012-04-18 01:56:21 - GuideAudio] Launch canceled!
我不明白,因为该库似乎导入良好......我可以在 Eclipse 的“引用库”下看到它们。
我也在清单上写了:
<uses-library android:name="com.google.android.vending.expansion.downloader" />
<uses-library android:name="com.google.android.vending.licensing" />