【发布时间】:2021-08-04 14:24:08
【问题描述】:
我有一个使用 CSRMesh 库作为 AAR 模块的 android 应用程序。 AAR 本身是模糊的。当minifyEnabled 在build.gradle 中为 false 时,我的应用程序运行良好,但当我将其设置为 true 时,应用程序崩溃了。
以下代码来自自定义 MeshLibraryManager 类,用于对库进行 API 调用。
private void enableBluetooth() {
try {
mCurrentChannel = MeshChannel.BLUETOOTH;
isChannelReady = false;
mBtBearer = new BluetoothBearer(this, mContext.get());
if (mService != null) {
mService.setBearer(mBtBearer); // crash occurs in this line
mService.setBluetoothBearerEnabled(mBtBearer);
}
EventBus.getDefault().post(new MeshSystemEvent(MeshSystemEvent.SystemEvent.CHANNEL_NOT_READY));
} catch (Exception e) {
e.printStackTrace();
}
}
在此代码块中,mService 是库中 MeshService 类的一个实例。
我在应用程序崩溃的行中添加了一条评论。如果我注释掉该行及其下方的行,应用程序不会崩溃,但我无法执行所需的蓝牙操作。
这是崩溃的完整堆栈跟踪:
2021-05-14 16:21:48.994 27372-27372/com.example.myApp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myApp, PID: 27372
java.lang.ExceptionInInitializerError
at com.csr.internal.mesh_le.g0.a(SourceFile:70)
at com.csr.internal.mesh_le.f.l(SourceFile:269)
at com.csr.csrmesh2.MeshService.y(SourceFile:309)
at com.example.scanner.api.MeshLibraryManager.v(SourceFile:336)
at com.example.scanner.api.MeshLibraryManager.o(SourceFile:59)
at com.example.scanner.api.MeshLibraryManager$b.onServiceConnected(SourceFile:595)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1738)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1770)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6820)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:922)
我已经尝试为所需的类添加 proguard 规则,无论我可以从代码和堆栈跟踪中找到什么,但没有任何效果。
请建议我该如何解决这个问题。
【问题讨论】:
标签: android proguard obfuscation minify aar