为什么在我以前从未需要它时开始使用 -libraryjars? [英] Why start using -libraryjars when I never needed it before?

查看:27
本文介绍了为什么在我以前从未需要它时开始使用 -libraryjars?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我将 ADT 从 16 更新到 18(这要求 Proguard 从 4.6 更新到 4.8)以来,Proguard 的行为一直非常奇怪(并且不一致?).

Since I updated ADT from 16 to 18 (which mandated Proguard update from 4.6 to 4.8), Proguard has been acting very weirdly (and inconsistently?).

最近出现的此类问题是,当我尝试导出已签名(发布)APK 时,收到以下错误:

The latest such problem is when I try to export a signed (release) APK, I receive the following errors:

Proguard returned with error code 1. See console
Warning: com.bta.LibProj2: can't find referenced class com.bta.R$string
Warning: com.bta.MyDlg1: can't find referenced class com.bta.R$string
Warning: com.bta.MyMenu: can't find referenced class com.bta.R$menu
Warning: com.bta.R: can't find referenced class com.bta.R$attr
Warning: com.bta.R: can't find referenced class com.bta.R$drawable
Warning: com.bta.R: can't find referenced class com.bta.R$menu
Warning: com.bta.R: can't find referenced class com.bta.R$string
Warning: com.bta.myapp.MyAppActivity$1: can't find referenced class com.bta.myapp.MyAppActivity
Warning: com.bta.myapp.MyAppActivity$ELicenseResponse: can't find referenced class com.bta.myapp.MyAppActivity
Warning: com.bta.myapp.MyAppActivity$MyLicenseCheckerCallback$1: can't find referenced class com.bta.myapp.MyAppActivity$MyLicenseCheckerCallback
Warning: com.bta.myapp.MyAppActivity$MyLicenseCheckerCallback$1: can't find referenced class com.bta.myapp.MyAppActivity
Warning: com.bta.myapp.R$array: can't find referenced class com.bta.myapp.R
Warning: com.bta.myapp.R$layout: can't find referenced class com.bta.myapp.R
Warning: com.bta.myapp.R$xml: can't find referenced class com.bta.myapp.R
Warning: there were 49 unresolved references to classes or interfaces.
         You may need to specify additional library jars (using '-libraryjars').
java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:321)
    at proguard.ProGuard.initialize(ProGuard.java:212)
    at proguard.ProGuard.execute(ProGuard.java:87)
    at proguard.ProGuard.main(ProGuard.java:493)

我确实注意到在 proguard.cfg 中添加 -libraryjars 的建议,但我以前从未需要这样做(而且我没有更改代码中的任何内容,我所做的只是更新 Proguard从 4.6 到 4.8).这是否表明我的开发环境配置有问题?

I did notice the recommendation to add -libraryjars in proguard.cfg, but I never needed to do this before (and I didn't change anything in my code, all I did was updating Proguard from 4.6 to 4.8). Does this suggest something wrong in my development environment configuration?

此外,我检查了 Proguard 的故障排除部分,了解 找不到引用的类:它指的是忘记或忽略通过 -libraryjars(我承认)指定一个库,但我从未指定任何库并且它总是以前工作过!发生了什么变化?

Also, I checked Proguard's Troubleshooting section for Can't find referenced class: It refers to forgetting or ignoring to specify a library via -libraryjars (which I admit), but I never specified any library and it always worked before! What changed?

我的 proguard.cfg 文件 BTW 开头为:

My proguard.cfg file BTW starts with:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

知道发生了什么吗?为什么 Proguard 开始让我如此艰难?(我使用它已经一年多了)我的系统配置中是否缺少一些基本的东西?

Any idea what's going on? Why did Proguard start giving me such hard time? (I coasted very smoothly with it for over a year now) Is there something fundamental I am missing in my system configuration?

顺便说一句,我确实尝试通过在 -libraryjars 行中指定所有库来添加我一直在使用的库,但是 Proguard 的行为只会变得更糟:它会失败而不提供任何错误日志我上面引用的.

BTW, I did try to add the libraries I have been using by specifying all of them in -libraryjars lines, but Proguard's behavior only got worse: It would fail without giving any of the error log that I quoted above.

推荐答案

问题已解决.在 SO 中大量搜索线索后,我终于找到了这个提示,正是 Proguard 的开发者本人:

Problem solved. After much search for clues here in SO, I finally found this hint by no other than Proguard's developer himself:

-dontwarn scala.**

我没有使用任何包含scala"的东西,我也不知道 Scala 是什么.但这给了我在我自己的应用程序包上放置一个-dontwarn的想法:

I'm not using anything that contains "scala" and I don't know what scala is. But that gave me the idea of placing a -dontwarn on my own application package:

-dontwarn com.bta.**

成功了.

为了记录,让我找到这个提示的搜索词组是:proguard admob找不到引用的类".

For the record, the search phrase that led me to finding this hint was: proguard admob "can't find referenced class".

附言Proguard 的建议 您可能需要指定额外的库 jar(使用 '-libraryjars') 甚至没有朝着正确的方向...

P.S. Proguard's suggestion You may need to specify additional library jars (using '-libraryjars') wasn't even in the right direction...

更新:虽然 -dontwarn com.bta.** 允许生成签名的 APK,但当我尝试启动它时它崩溃了:

UPDATE: While -dontwarn com.bta.** allowed producing a signed APK, it crashed as soon as I tried to launch it with:

ClassNotFoundException: com.bta.myapp.MyAppActivity in loader dalvik.system.PathClassLoader[/data/app/com.bta.myapp.myapp-1.apk]. 

什么样的恶梦.

What a nightmare.

更新 2: -dontwarn com.bta.** 结果太包容了.我改成:

UPDATE 2: -dontwarn com.bta.** turned out to be way too inclusive. I changed it to:

-dontwarn com.bta.myapp.MyAppActivity.R**

现在一切运行良好,没有发生任何事故.真是噩梦.

And now everything runs well without incident. What a nightmare.

在调试那些应该可以节省时间的工具上浪费了太多时间之后,我发现了问题的根源.这是 Android SDK 工具中的一个错误.它被记录为已在 r17 中解决,但我使用的是今天(2012 年 6 月 18 日)的最新版本,尚未解决!(请参阅评论 24).评论 25 还描述了现在允许我使用的解决方法继续我的实际开发.

After wasting way too much time on debugging the very tools that are supposed to save me time, I discovered the source of the problem. It's a bug in the Android SDK tools. It is documented as have been solved in r17, but I am using the latest of today (June 18 2012) and it hasn't been solved! (see comment 24). Comment 25 also describes the workaround that allows me now to proceed with my actual development.

错误是复杂系统中的现实.但是,无论是 Proguard 还是向 Proguard 提供输入的构建工具都无法提供任何有用的错误消息(实际上它们恰恰相反),这一事实表明 Android 开发工具的方法论"出了点问题Google 推荐.

Bugs are fact of life in complex systems. But the fact that neither Proguard nor the build tools that feed input to Proguard could provide any helpful error message (in fact they did exactly the opposite), suggests something is broken in the "methodology" of the Android development tools recommended by Google.

这篇关于为什么在我以前从未需要它时开始使用 -libraryjars?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆