我在 Android 应用程序 .apk 中使用的库是否会与另一个应用程序中使用的库发生冲突?
我将 jets3t 链接到一个测试应用程序中,并得到了我在安装过程中尚未看到的日志猫。
02-08 12:21:11.825: DEBUG/PackageParser(1086): Scanning package: /data/app/vmdl28891.tmp
02-08 12:21:12.059: DEBUG/PackageManager(1086): Scanning package org.jets3t
02-08 12:21:12.075: INFO/PackageManager(1086): /data/app/org.jets3t-1.apk changed; unpacking
02-08 12:21:12.082: DEBUG/installd(1009): DexInv: --- BEGIN '/data/app/org.jets3t-1.apk' ---
02-08 12:21:12.481: DEBUG/dalvikvm(26867): creating instr width table
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/Decoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/BinaryDecoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/Encoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/BinaryEncoder;' has an earlier definition; blocking out
... many more ...
'Lorg/apache/commons/logging/impl/WeakHashtable$Entry;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable$Referenced;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable$WeakKey;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable;': multiple definitions
02-08 12:21:13.168: INFO/dalvikvm(26867): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/logging/LogFactory;'
... many more ...
02-08 12:21:13.364: INFO/dalvikvm(26867): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/logging/LogFactory;'
02-08 12:21:13.387: DEBUG/libgps(1086): GpsInterface_inject_location( 37.378289, -122.059655, 897.000 )
02-08 12:21:13.387: DEBUG/dalvikvm(26867): DexOpt: load 111ms, verify 540ms, opt 21ms
02-08 12:21:13.543: DEBUG/installd(1009): DexInv: --- END '/data/app/org.jets3t-1.apk' (success) ---
02-08 12:21:13.551: INFO/ActivityManager(1086): Force stopping package org.jets3t uid=10084
02-08 12:21:13.559: DEBUG/PackageManager(1086): Activities: org.jets3t.MainActivity
02-08 12:21:13.832: INFO/installd(1009): move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex
02-08 12:21:13.832: DEBUG/PackageManager(1086): New package installed in /data/app/org.jets3t-1.apk
我正在将其视为共享库覆盖。如果是的话,我想知道这是否是我做错了什么的结果?如果我覆盖,其他应用程序崩溃的可能性有多大?当然,任何正确创建的库都将向后兼容..我猜Android包mgr不会用旧版本替换包?
加上“多重定义”? “没有解决模糊类”?
哦是的..测试应用程序到目前为止似乎工作正常:)
谢谢。我想我需要去阅读 pkg 安装、加载和链接,哈哈。
I linked jets3t into a test app and got logcats I've not yet seen during install ..
02-08 12:21:11.825: DEBUG/PackageParser(1086): Scanning package: /data/app/vmdl28891.tmp
02-08 12:21:12.059: DEBUG/PackageManager(1086): Scanning package org.jets3t
02-08 12:21:12.075: INFO/PackageManager(1086): /data/app/org.jets3t-1.apk changed; unpacking
02-08 12:21:12.082: DEBUG/installd(1009): DexInv: --- BEGIN '/data/app/org.jets3t-1.apk' ---
02-08 12:21:12.481: DEBUG/dalvikvm(26867): creating instr width table
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/Decoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/BinaryDecoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/Encoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/BinaryEncoder;' has an earlier definition; blocking out
... many more ...
'Lorg/apache/commons/logging/impl/WeakHashtable$Entry;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable$Referenced;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable$WeakKey;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable;': multiple definitions
02-08 12:21:13.168: INFO/dalvikvm(26867): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/logging/LogFactory;'
... many more ...
02-08 12:21:13.364: INFO/dalvikvm(26867): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/logging/LogFactory;'
02-08 12:21:13.387: DEBUG/libgps(1086): GpsInterface_inject_location( 37.378289, -122.059655, 897.000 )
02-08 12:21:13.387: DEBUG/dalvikvm(26867): DexOpt: load 111ms, verify 540ms, opt 21ms
02-08 12:21:13.543: DEBUG/installd(1009): DexInv: --- END '/data/app/org.jets3t-1.apk' (success) ---
02-08 12:21:13.551: INFO/ActivityManager(1086): Force stopping package org.jets3t uid=10084
02-08 12:21:13.559: DEBUG/PackageManager(1086): Activities: org.jets3t.MainActivity
02-08 12:21:13.832: INFO/installd(1009): move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex
02-08 12:21:13.832: DEBUG/PackageManager(1086): New package installed in /data/app/org.jets3t-1.apk
I'm reading that as shared library overwrites. If it is, I'm wondering if this is a result of something I did wrong? If I overwrite, what are the chances that other apps could break? Of course any properly created library will be backward compatible .. and I guess Android package mgr would not replace a package with an older variant?
Plus "multiple definitions"? "not resolving ambiguous class"?
Oh yeah.. the test app seems to work fine so far :)
Thanks. Guess I need to go read up on pkg install, load, and link lol.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信,真正损坏正确保护的设备上的另一个应用程序的唯一方法是替换它所依赖的 .apk。
在我看来,您正在安装一个 .apk,其中包含与该设备的平台库中的某些内容重复的类。新的重复项将被忽略。这并不罕见,因为平台中有各种极具吸引力的“私有”功能,但 SDK 中没有“标头”(抱歉,术语错误,但传达了这个想法)。如果不包含存根来满足编译器的要求(或使用反射在运行时查找真正的类),这使得编写代码变得困难。在安装时,这些存根会被忽略,并显示您所看到的警告消息。
这不一定是好的做法,但只要设备上的私有功能继续按预期工作,它往往就会起作用 - 即,它可能会在操作系统升级或程序安装在不同的设备上时中断。由于这个原因,Android 人员非常坚持地告诉你不要使用私有功能。
尽管存在错误/警告消息,但仍能正常工作的代码中保留的错误/警告消息也不是很好的做法,而且不幸的是,这确实是 Android 堆栈本身特有的东西。
I believe the only way you'd actually damage another application on a properly secured device is if you replace an .apk it depends on.
It looks to me more like you are installing an .apk which contains classes that duplicate some in the platform libraries of that device. The new duplicates are being ignored. This is not uncommon, as there is a variety of highly attractive 'private' functionality in the platform which doesn't have "headers" (sorry, wrong term, but conveys the idea) in the sdk. This makes it hard to write against without including stubs to satisfy the compiler (or using reflection to find the real classes at runtime). At install time those stubs get ignored with warning messages as you are seeing.
This is not necessarily good practice, but it tends to work as long as the private functionality on the device continues to work as expected - ie, it can break in an an OS upgrade or when the program is installed on a different device. The Android people are pretty persistent in telling you not to use private functionality for that reason.
Error/warning message remaining in shipping code that works despite them is also not great practice, and is unfortunately something really endemic to the android stack itself.