eclipse 包括 Google Play 下载器库 | APK 文件扩展库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10199590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Including Google Play Downloader Library | APK File Expansion Library
提问by Floy
I'm following dev guide at http://developer.android.com/guide/market/expansion-files.htmlin order to download additional assets to my apk.
我正在遵循http://developer.android.com/guide/market/expansion-files.html 上的开发指南,以便将其他资产下载到我的 apk。
I've done all the part about the importation of libraries, etc .. I've also implemented the samples code in my main program (in order to detect if expansion files are already downloaded, if we need to download them and launch the download, etc ..)
我已经完成了关于库导入等的所有部分。我还在我的主程序中实现了示例代码(为了检测扩展文件是否已经下载,如果我们需要下载它们并启动下载, 等等 ..)
I have no errors in eclipse, but when I launch the app and starting to call the methods and classes from the library, I have various crashes:
我在 eclipse 中没有错误,但是当我启动应用程序并开始从库中调用方法和类时,我遇到了各种崩溃:
1 - First, at the installation, adb says that the libraries couldn't be found.. :
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!
Here is a screenshot of how I have tried to import my libraries: http://floy.fr/perso/floy/expfiles/4.PNG
这是我如何尝试导入我的库的屏幕截图:http: //floy.fr/perso/floy/expfiles/4.PNG
I have imported the libraries with project import in the Java Build Path like part a), in my main project properties: (imported the licence library in the download library that way too)
我已经在 Java Build Path 中导入了带有项目导入的库,如a)部分,在我的主项目属性中:(也以这种方式导入了下载库中的许可证库)
I've also tried to import only the jars like in part b)(no error at installation with this one)
我还尝试仅导入b)部分中的 jar (安装时没有错误)
and with the Android Library import like in part c)(It seems to be the one recommended in the dev guide, but I have compilation errors with this one, eclipse don't find some references and i can't build the project):
并使用c)部分中的 Android 库导入(这似乎是开发指南中推荐的那个,但我有编译错误,eclipse 找不到一些引用,我无法构建项目):
So, the jar importation seems to be the best, no errors at compilation and installation, but I have other errors after, when I'm making a call to the methodes and classes from the library:
所以,jar 导入似乎是最好的,在编译和安装时没有错误,但是当我从库中调用方法和类时,我有其他错误:
2 - In the app :
2 - 在应用程序中:
When i'm trying to use the helper in order to check the presence of the XAPKFiles with this method :
当我尝试使用帮助程序以使用此方法检查 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;
}
I have this crash in DDMS:
我在 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.access0(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)
This crash happen when i'm using the method 1 or 2 when i'm importing the libraries.
当我在导入库时使用方法 1 或 2 时,会发生这种崩溃。
I have tried to update ant to latest 1.8.3 because I read that 1.7.1 could have some issues with library imports .. with no success on resolving my problems .
我试图将 ant 更新到最新的 1.8.3,因为我读到 1.7.1 可能在库导入方面存在一些问题……但没有成功解决我的问题。
My main application is on Google API 8 (Android 2.2)
我的主要应用程序在 Google API 8 (Android 2.2) 上
I have searched a lot of things in order to make this to work but .. now i'm completely out of ideas !
我已经搜索了很多东西以使它起作用但是..现在我完全没有想法了!
If someone knows how to get this working that would be very kind :p
如果有人知道如何让这个工作,那将是非常友好的:p
Sorry for this long post and sorry for my english, if i made misspelling mistakes, that's because i'm french :p
抱歉这篇长文,抱歉我的英语,如果我拼错了,那是因为我是法国人:p
EDIT:I have tried the downloader sample code, with the library import method c), I have no compilation errors this time, but during the installation :
编辑:我已经尝试了下载器示例代码,使用库导入方法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!
I don't understand because the library seems to be well imported ... I can see them under "Referenced Library" in Eclipse.
我不明白,因为该库似乎已经很好地导入了......我可以在 Eclipse 的“参考库”下看到它们。
I've also write on the manifest :
我也在清单上写过:
<uses-library android:name="com.google.android.vending.expansion.downloader" />
<uses-library android:name="com.google.android.vending.licensing" />
采纳答案by WarrenFaith
The answer might be in this answer to a similar question: https://stackoverflow.com/a/10109546/180538
答案可能在类似问题的答案中:https: //stackoverflow.com/a/10109546/180538
I had this issue two days ago, too, and the answer solved it. Especially read the last paragraph.
前两天我也有这个问题,答案解决了。尤其是阅读最后一段。
The <uses-library>
tags are not meant to be used for third party stuff, only for already existing libraries installed on the devices. Like Maps, which is installed on each official android device (Amazon Kindle is not an official android device, just as an example).
该<uses-library>
标签并不意味着用于第三方的东西,只有在设备上安装现有的库。就像地图一样,它安装在每个官方的安卓设备上(亚马逊Kindle 不是官方的安卓设备,仅作为示例)。
I am also not sure if you have added your library projects to your project andlinking the jars at the same time. That might also cause trouble.
我也不确定您是否已将库项目添加到您的项目并同时链接了 jars。这也可能会带来麻烦。
回答by Floy
For People who are reading this, The right method to use to import the Expansion Library is the one i referred as c)in my first post.
对于正在阅读本文的人,用于导入扩展库的正确方法是我在第一篇文章中称为c)的方法。
Take care of your path length when you are importing project library in your main project. My path was too long due to my Android SDK installation folder which was not on the same drive as my workspace. The library import may fail because of that. ( took me one day to realize .. -_- )
在主项目中导入项目库时,请注意路径长度。由于我的 Android SDK 安装文件夹与我的工作区不在同一驱动器上,我的路径太长。因此,库导入可能会失败。(花了我一天的时间才意识到.. - _- )
回答by Bannorani
I think the real issue here is the one described in this answer: Eclipse is not able to resolve path names if the included library project and the referencing project are in different drives. E.g. Library in C: and Referencing project in D:
我认为这里的真正问题是这个答案中描述的问题:如果包含的库项目和引用项目位于不同的驱动器中,则 Eclipse 无法解析路径名。例如 C: 中的库和 D: 中的引用项目