Android proguard,设备上的空指针异常

2024-04-04

当我在手机上安装我的应用程序时,出现异常。它无需 proguard 即可工作。我的配置有什么问题?非常感谢!该配置是我在某处找到的默认 Android 配置。不知道发生了什么事

D/AndroidRuntime(15388): Shutting down VM
W/dalvikvm(15388): threadid=1: thread exiting with uncaught exception (group=0x40c3a1f8)
E/AndroidRuntime(15388): FATAL EXCEPTION: main
E/AndroidRuntime(15388): java.lang.NullPointerException
E/AndroidRuntime(15388): at aV.setViewValue(SourceFile:163)
E/AndroidRuntime(15388): at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:168)
E/AndroidRuntime(15388): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
E/AndroidRuntime(15388): at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
E/AndroidRuntime(15388): at android.widget.AbsListView.obtainView(AbsListView.java:2214)
E/AndroidRuntime(15388): at android.widget.ListView.makeAndAddView(ListView.java:1774)
E/AndroidRuntime(15388): at android.widget.ListView.fillDown(ListView.java:672)
E/AndroidRuntime(15388): at android.widget.ListView.fillFromTop(ListView.java:732)
E/AndroidRuntime(15388): at android.widget.ListView.layoutChildren(ListView.java:1625)
E/AndroidRuntime(15388): at android.widget.AbsListView.onLayout(AbsListView.java:2044)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
E/AndroidRuntime(15388): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
E/AndroidRuntime(15388): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
E/AndroidRuntime(15388): at android.view.View.layout(View.java:11418)
E/AndroidRuntime(15388): at android.view.ViewGroup.layout(ViewGroup.java:4224)
E/AndroidRuntime(15388): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1628)
E/AndroidRuntime(15388): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2585)
E/AndroidRuntime(15388): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(15388): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(15388): at android.app.ActivityThread.main(ActivityThread.java:4507)
E/AndroidRuntime(15388): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(15388): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(15388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
E/AndroidRuntime(15388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
E/AndroidRuntime(15388): at dalvik.system.NativeStart.main(Native Method)

这是我的混淆器配置

-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar

-libraryjars /libs/android-support-v13.jar



#
# This ProGuard configuration file illustrates how to process Android
# applications.
# Usage:
#     java -jar proguard.jar @android.pro
#
# If you're using the Android SDK (version 2.3 or higher), the android tool
# already creates a file like this in your project, called proguard.cfg.
# It should contain the settings of this file, minus the input and output paths
# (-injars, -outjars, -libraryjars, -printmapping, and -printseeds).
# The generated Ant build file automatically sets these paths.

# Specify the input jars, output jars, and library jars.
# Note that ProGuard works with Java bytecode (.class),
# before the dex compiler converts it into Dalvik code (.dex).



    # Save the obfuscation mapping to a file, so you can de-obfuscate any stack
    # traces later on.

    -printmapping bin/classes-processed.map

    # You can print out the seeds that are matching the keep options below.

    #-printseeds bin/classes-processed.seeds

    # Preverification is irrelevant for the dex compiler and the Dalvik VM.

    -dontpreverify

    # Reduce the size of the output some more.

    -repackageclasses ''
    -allowaccessmodification

    # Switch off some optimizations that trip older versions of the Dalvik VM.

    -optimizations !code/simplification/arithmetic

    # Keep a fixed source file attribute and all line number tables to get line
    # numbers in the stack traces.
    # You can comment this out if you're not interested in stack traces.

    -renamesourcefileattribute SourceFile
    -keepattributes SourceFile,LineNumberTable

    # RemoteViews might need annotations.

    -keepattributes *Annotation*

    # Preserve all fundamental application classes.

    -keep public class * extends android.app.Activity
    -keep public class * extends android.app.Application
    -keep public class * extends android.app.Service
    -keep public class * extends android.content.BroadcastReceiver
    -keep public class * extends android.content.ContentProvider

    # Preserve all View implementations, their special context constructors, and
    # their setters.

    -keep public class * extends android.view.View {
        public <init>(android.content.Context);
        public <init>(android.content.Context, android.util.AttributeSet);
        public <init>(android.content.Context, android.util.AttributeSet, int);
        public void set*(...);
    }

    # Preserve all classes that have special context constructors, and the
    # constructors themselves.

    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }

    # Preserve all classes that have special context constructors, and the
    # constructors themselves.

    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }

    # Preserve the special fields of all Parcelable implementations.

    -keepclassmembers class * implements android.os.Parcelable {
        static android.os.Parcelable$Creator CREATOR;
    }

    # Preserve static fields of inner classes of R classes that might be accessed
    # through introspection.

    -keepclassmembers class **.R$* {
      public static <fields>;
    }

    # Preserve the required interface from the License Verification Library
    # (but don't nag the developer if the library is not used at all).

    #-keep public interface com.android.vending.licensing.ILicensingService

    #-dontnote com.android.vending.licensing.ILicensingService

    # The Android Compatibility library references some classes that may not be
    # present in all versions of the API, but we know that's ok.

    -dontwarn android.support.**

    # Preserve all native method names and the names of their classes.

    -keepclasseswithmembernames class * {
        native <methods>;
    }

    # Preserve the special static methods that are required in all enumeration
    # classes.

    -keepclassmembers class * extends java.lang.Enum {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }

    # Explicitly preserve all serialization members. The Serializable interface
    # is only a marker interface, so it wouldn't save them.
    # You can comment this out if your application doesn't use serialization.
    # If your code contains serializable classes that have to be backward 
    # compatible, please refer to the manual.

    #-keepclassmembers class * implements java.io.Serializable {
    #    static final long serialVersionUID;
    #    static final java.io.ObjectStreamField[] serialPersistentFields;
    #    private void writeObject(java.io.ObjectOutputStream);
    #    private void readObject(java.io.ObjectInputStream);
    #    java.lang.Object writeReplace();
    #    java.lang.Object readResolve();
    #}

    # Your application may contain more items that need to be preserved; 
    # typically classes that are dynamically created using Class.forName:

    # -keep public class mypackage.MyClass
    # -keep public interface mypackage.MyInterface
    # -keep public class * implements mypackage.MyInterface

    # Needed by google-api-client to keep generic types and @Key annotations accessed via reflection
    -keepclassmembers class * {
      @com.google.api.client.util.Key <fields>;
    }

    -keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault,*Annotation*

    -dontwarn sun.misc.Unsafe





    -keepattributes 
    -dontoptimize


    #-dontshrink 

设置场景

我目前有完全相同的问题。我有一个带有布局充气机的自定义适配器的完美工作代码,使用以下格式parent and false作为第二个和第三个参数。

由于代码运行良好,没有混淆,我有足够的信心忽略 stackoverflow 上有关的所有问题和回复null由于错误使用 Android API 而返回视图。

如果您也遇到了没有混淆的问题,请忽略此答案和问题并继续!检查这些问题 https://stackoverflow.com/questions/10204262/nullpointerexception-in-custom-adapter-getview

我将尽力在这个答案中报告我的发现。这个答案可能会随着时间的推移而增长。跳到底部的结论如果您渴望了解最新消息。

快速而肮脏的解决方案

这里直接的解决方案是更新您的混淆器配置,以排除您的代码在混淆后失败的类。

在你的 proguard 配置文件中应该是这样的:

-keep class * extends your.company.secret.package

有关 proguard 的更多信息请开始查看此处 http://developer.android.com/tools/help/proguard.html。还要确保您至少拥有 Android 项目所需的最低限度的 proguard 配置文件。检查这个例子 http://code.google.com/p/google-gson/source/browse/trunk/examples/android-proguard-example/proguard.cfg.

映射回您的源代码

在研究这个问题时,您可能会对混淆之前该类的原始名称感兴趣。这应该会让事情变得容易得多。您可以在项目的 bin 文件夹中的 mapping.txt 文件的 proguard 文件夹中找到此映射。

/bin/proguard/mapping.txt

固定到以下代码行

就我而言,我能够确定以下代码行的错误。这些行仅出现在发生故障的适配器中,而其他代码在工作适配器中是常见的。以下所有代码都是getView(final int position, View convertView, final ViewGroup parent):View method

holder.layout.removeAllViews();
TextView tView;
for (final String text : mItems.getTextList()) {
    tView = new TextView(mContext);
    tView.setTextSize(14);
    tView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tView.setText(text);
    holder.layout.addView(tView);
}

如果我只是删除addView() and removeAllViews()打电话比一切顺利。

安卓源代码

我的第一个想法是检查该行代码的源代码。我在堆栈跟踪中找到了以下点。

11-20 14:19:40.709: E/AndroidRuntime(22236): FATAL EXCEPTION: main
11-20 14:19:40.709: E/AndroidRuntime(22236): Process: your.company.secret.package, PID: 22236
11-20 14:19:40.709: E/AndroidRuntime(22236): java.lang.NullPointerException
11-20 14:19:40.709: E/AndroidRuntime(22236):    at android.widget.AbsListView.obtainView(AbsListView.java:2265)

The AbsListView 的源代码可以在 grepcode 上找到 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/widget/AbsListView.java#AbsListView.obtainView%28int,boolean%5B%5D%29然而,查看该代码并没有给我很大的勇气在那里找到解决方案。相反,我转向了其他资源。可能稍后会回到这个话题。

我在 Android 4.4 设备上执行此代码,因此行号甚至不匹配。

在 4.3 设备上测试

正确的代码行是 2177。与此行匹配:

child = mAdapter.getView(position, null, this);

示例项目

See https://github.com/hanscappelle/so-10822397 https://github.com/hanscappelle/so-10822397对于示例项目。您需要 Android Studio(Beta)0.8.2 和最新的构建工具。我还必须手动获取 proguard-android.txt 文件并将其放置到位。

您可以注释掉适配器中作用于静态 ViewHolder 类的布局字段的行。一旦启用 proguard 并且应用程序在设备上运行,这些就会失败。

我接下来计划做的事情

  • (完成)我的代码中还有其他适配器,即使在混淆后也能正常工作。我会检查这些与失败的差异

  • (完成)我真的必须检查 4.3 设备,这样我才能正确查看 Android 源代码。

  • (完成)创建示例项目

  • TODO 通过示例项目进行完整分析

结论

似乎与动态添加视图有关getView()自定义适配器的方法。与代码混淆相结合。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android proguard,设备上的空指针异常 的相关文章

  • EditText 中的验证允许 IP 或 Web Url 主机

    我需要对我的 EditText 进行验证 以便它允许我输入有效的 IP 地址格式 即示例 132 0 25 225 or 网址格式 www 例如 www example com 逻辑是 如果用户首先输入任何数值 则验证 IP 将执行操作 否
  • 已发布的 Flutter 应用程序在启动时崩溃

    编辑 此问题的解决方案是将您的 flutter 版本升级到较新的 dev 版本 then 1 7 0 您还可以上传单独的 APK 版本 但我个人不喜欢这个选项 请确保您没有从 flutter github 开发存储库下载 错误的构建 因为那
  • Android KeyBoard.Key 禁用图标 预览特殊键?

    我通过实现 KeyboardView OnKeyboardActionListener 接口来自定义自己的软键盘 按下按键时 将显示预览弹出窗口 我的问题是如何禁用 SHIFT 和 DELETE 等特殊键的预览弹出窗口 我尝试将 andro
  • Android 上的 Firebase:如何检查 Firebase 身份验证失败原因?

    我在 Android 上使用 Firebase 和 Firebase Auth 功能 I try FirebaseAuth signInWithEmailAndPassword如果失败 我想知道为什么登录过程失败 The signInWit
  • 显示警报或收到通知时的视图

    我正在关注this http tokudu com 2010 how to implement push notifications for android 显示的教程通知 on an 安卓设备 当我在设备上运行该应用程序时 状态栏上会出现
  • 如何在出现“无法解析放置符号”错误时向哈希图添加键和值

    我正在与安卓工作室 https en wikipedia org wiki Android Studio1 4 1 我刚刚创建了一个 Hashmap 并正在遵循有关如何填充和操作它的教程 Java 语言 但是 我收到 无法解析符号放置 错误
  • Android Studio:lambda 不起作用[重复]

    这个问题在这里已经有答案了 当尝试使用 lambda 表达式时 我遇到了一些 Gradle 构建错误 错误 41 100 错误 source 1 7 不支持 lambda 表达式 使用 source 8 或更高版本来启用 lambda 表达
  • 如何使用闹钟音量和 setAudioAttributes 来播放铃声?

    所以我正在尝试了解音频属性 这是我到目前为止所拥有的 alarm getSound will return a proper URI to pick a ringtone Ringtone tone RingtoneManager getR
  • 访问角落里的存储

    我能找到的与文件存储有关的最接近文档的是这个帖子 http nookdeveloper zendesk com entries 20257971 updated what are the size constraints on my app
  • Android中不同线程的数据库访问

    我有一个在 AsyncTasks 中从互联网下载数据的服务 它解析数据并将其存储在数据库中 该服务持续运行 当服务写入数据库时 活动会尝试从数据库中读取更改 我有一个数据库助手 有多种写入和读取方法 这会导致问题吗 可能尝试从两个不同的线程
  • android 确定设备是否采用从右到左的语言/布局

    有没有办法确定设备是否使用从右到左的语言 例如阿拉伯语 而不是从左到右的语言 英语 与较旧的 API 级别 低至 10 兼容的东西是必要的 SOLUTION 我最终在接受的答案中使用了 xml 方法 接下来 我还添加了此处指示的代码 以应对
  • 从多个选项卡中的编辑文本字段获取文本

    我正在尝试创建一个使用选项卡作为输入表单的 Android 应用程序 基本上 我希望对其进行设置 以便用户可以在一个选项卡上输入一些信息 然后提交该信息 或者转到另一个选项卡并输入更多信息 然后从两个选项卡提交信息 我正在使用操作栏和片段来
  • Google 移动广告和 Kindle Fire

    我最近用 Google 移动广告替换了 AdMob 库 对此我有一个疑问 广告会出现在 Amazon Kindle Fire 设备上吗 我问这个是因为我知道 Google 移动广告依赖于 Google Play 服务 所以我有点困惑 Goo
  • 如何从android获取应用程序安装时间

    我尝试了一些方法 但没有成功 请帮助我 PackageManager pm context getPackageManager ApplicationInfo appInfo pm getApplicationInfo app packag
  • 通过列表视图检查动态生成的复选框时遇到问题

    我知道其他成员已经提出了这个问题 一些成员也给出了解决方案 但问题是我没有找到任何适合我的应用程序的解决方案 我正在创建一个应用程序 其中我有一个屏幕 它将显示动态列表视图 其中包含列表项 复选框和三个文本视图 一个用于候选人姓名 另外两个
  • 不显示 WRITE_EXTERNAL_STORAGE 的权限对话框

    I want to download a file using DownloadManager And DownloadManager wants to WRITE EXTERNAL STORAGE permission I have in
  • Android:打开和关闭SQLite数据库

    我正在开发Android应用程序 我经常在其中访问本地数据库 该数据库可以从不同的主题访问 因此我遇到了数据库的协调问题 我使用以下open and close method public void open mDb mDbHelper g
  • 如何获取android手机型号、版本、sdk详细信息?

    如何获取android手机型号 版本 sdk详细信息 首先 看看 android sdk 页面上的这些 Build 类 http developer android com reference android os Build html h
  • 如何在Android中解析xml类型的HTTPResponse

    我有一个 Android 应用程序 我使用 POST 方法来获取响应 这是我的代码 HttpResponse httpResponse httpclient execute httppost HttpEntity resEntity htt
  • putFragment() - 片段 x 当前不在 FragmentManager 中

    上面的标题被问了很多次 但答案似乎与FragmentStatePagerAdapter这与我的问题无关 我正在使用该方法putFragment Bundle String Fragment 直接地 The 安卓文档 http develop

随机推荐

  • 如何让ListView在转换到另一个路线时保留其滚动?

    我想在我的颤动应用程序中完成滑动到右侧的转换 问题是路线转换有点创建我想要从中转换的页面的新实例 所以ListView滚动重置 看视频 https youtu be PdLhyvNoU8 这就是我创建新路线的方式 oldRoute need
  • dompdf 图像不是真实图像,无法读取或为空

    我在使用 dompdf 时遇到问题 我插入的图像在转换为 pdf 文件时无法读取 当我使用将其加载到 dompdf 时 php方法 img src gt 我得到一个带有 X 的方框缩略图 它说 图像不是真实图像 不可读或为空 用文本打印我的
  • Nodejs JOIN 查询:格式化 JSON 输出

    我正在制作一个非常简单的 RIGHT JOIN 查询 但我无法正确格式化输出 这是查询 connection query sql SELECT users rides FROM users RIGHT JOIN rides ON users
  • 需要帮助 Discord 机器人队列

    我一直在尝试为不和谐机器人和我的 gt q命令基本上工作为join play queue同时 问题是它只能同时对 2 首歌曲进行排队 所以我需要帮助使其对多首歌曲进行排队 queues check queue def check queue
  • 重复 data.frame 的每一行列中指定的次数

    df lt data frame var1 c a b c var2 c d e f freq 1 3 扩展上面 data frame 的每行前两列 以便每行重复 freq 列中指定的次数 最简单的方法是什么 换句话说 从这里开始 df v
  • 如何将 Twitter 配置移出控制器? (导轨)

    我正在使用推特宝石 https github com sferik twitter通过斯费里克 我认为在控制器中存储我的 Twitter 应用程序的配置非常混乱 class HomeController lt ApplicationCont
  • 如何使用`[[`和`$`作为函数?

    我知道我可以这样做 x lt list a 1 b 1 y lt list a 1 JSON lt rep list x y 10000 sapply JSON a 然而 我在使用时遇到了困难 以同样的方式 sapply JSON a sa
  • 如何使用列表理解来模拟 sum()?

    是否可以使用 sum 来模拟类似的东西列表理解 http en wikipedia org wiki List comprehension Python 例如 我需要计算列表中所有元素的乘积 list 1 2 3 product magic
  • 发送多个请求时如何将结果与请求匹配?

    总结 正如其标题所示 Guzzle 允许一次发送多个请求以节省时间 如下所示文档 http docs guzzlephp org en latest http client client html sending requests resp
  • Google 地图静态 API 返回奇怪的图像

    我有一个页面 其静态地图 URI 的形式为 当我从任何浏览器访问此页面时 它显示得很好 但当我通过通过我们的 BES 连接的黑莓使用它时 但相同的无线网络 然后出现这个图像 有谁知道这张图是什么意思 你有超出使用限制 http code g
  • 如何获取自定义错误页面(Tomcat)中的消息?

    在 JSP 中 您可以使用response sendError int code String message 返回特定的错误代码 例如 404 表示未找到 和消息 只要您使用默认的丑陋的 Tomcat 错误页面 这些消息就可以正常显示 但
  • Javascript 在 window.open 之后调用函数

    我试图在 window open 函数完全加载后调用一个函数 然而 使用 onload 函数调用得太早了 所点击的 URL 将打开一个 Excel 电子表格 下载可能需要 2 秒到 1 分钟 一旦 window open 函数被调用 onl
  • MvvmCross iOS:如何绑定MapView Annotation跳转到另一个视图?

    当单击标注附件按钮时 如何绑定 MapView 的注释以切换到不同的视图 如何实现注释的 CalloutAccessoryControlTapped 方法 或者最好的方法是什么 这是我的代码 Register MapView public
  • 如何在惰性函数式编程语言中实现调试?

    我想知道如何用惰性函数语言实现调试 你能使用断点 打印语句和传统技术吗 这是个好主意吗 据我了解 纯函数式编程不允许有副作用 除了 monad 之外 执行顺序也无法保证 您是否必须为要测试的每个代码部分编写一个 monad 我想从这个领域更
  • 开发环境中应用程序内部的 Rails FactoryGirl

    我正在尝试在开发模式下在我的应用程序中使用 FactoryGirl gem 用于邮件测试more https github com glebm rails email preview issues 66 issuecomment 21595
  • 用户从下拉列表中选择项目后禁用 Android AutoCompleteTextView

    我用的是安卓系统AutoCompleteTextView with a CursorAdapter将自动完成功能添加到应用程序中 在视图的onItemClickListener 即 当用户触摸自动完成的下拉项之一时 我检索文本并将其放置在
  • 新手:XSLT 转换以验证 XML 文档中的规则

    我是 XSLT 的新手 我有一个 XML 文档 我需要使用 xslt 来验证 XML 文档中的某些规则 XML 和 xsl 文件将在 xsltproc 工具中使用 输出将是简单的 通过 或 失败 XML 示例
  • NSIS - 静默自动更新应用程序

    我有一个适用于我的 net c 应用程序的 NSIS 安装工具包 考虑到我已经将新的更新 新的 NSIS 应用程序版本 下载到本地计算机 有没有办法静默自动更新我的应用程序 谢谢 如果您需要检测命令行 Autoupdate yes incl
  • 为什么Xcode找不到这个头文件?

    您好 我收到一个 xcode 没有这样的文件或目录 import Three20Core h 我还注意到 当我输入 import 语句时 它会识别并帮助自动完成 Three20Core h 文件 但是当我编译时出现错误 这是 Three20
  • Android proguard,设备上的空指针异常

    当我在手机上安装我的应用程序时 出现异常 它无需 proguard 即可工作 我的配置有什么问题 非常感谢 该配置是我在某处找到的默认 Android 配置 不知道发生了什么事 D AndroidRuntime 15388 Shutting