我的应用程序在没有应用pro-guard-rules的情况下工作正常但出于安全考虑,我必须在我的应用程序中应用pro-guard-rules。 当我应用规则并尝试运行我的应用程序时,我收到了这些错误。
FATAL EXCEPTION: main
Process: com.nearely.nearelysales, PID: 4275
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nearely.nearelysales/com.nearely.nearelysales.activities.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.nearely.nearelysales.activities.MainActivity.k(Unknown Source)
at com.nearely.nearelysales.activities.MainActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
这是我的progurd-rules文件:
proguard-rules.pro
-injars libs
-outjars bin/classes-processed.jar
# -libraryjars C:\dev\android-sdk\platforms\android-23\android.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-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
-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*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
-keep class javax.ws.rs.** { *; }
-dontwarn org.immutables.gson.**
-dontwarn android.test.**
-dontwarn org.junit.**
答案 0 :(得分:4)
好像你已经使用了凌空,并且使用proguard崩溃了你的应用程序。 您可以将此行写入 proGuard 。
soup.findAll('td', {'class':['cell_ab team-home', 'cell_ab team-home bold ']})
答案 1 :(得分:0)
在您的应用程序中设置 Proguard Enabled 后,所有 Proguard 自定义规则取决于您是在应用程序的初始阶段还是中间或后期设置了 Proguard。
这意味着,如果您在应用中集成任何第三方库,则如果该库提供或支持 proguard,规则将自行设置。
2.中后期
<块引用>中间如果你在你的应用中设置了proguard并且你已经集成了许多第三方库,这意味着每个库都是没有规则的集成。然后,您需要在 proguard-rules.pro 文件中设置自定义规则。
app崩溃的场景有很多,一个是你使用的pojo类或者model类被proguard混淆了,需要在proguard-rules.pro文件中设置规则 喜欢:
-keep class * {
public private *;
}
或以其他方式根据要求使用以下代码
-dontwarn com.squareup.okhttp.**
-ignorewarnings
-keep class * {
public private *;
}
-keep class com.google.android.gms.* { *; }
-dontwarn com.google.android.gms.**
-dontwarn org.xmlpull.v1.**
-dontnote org.xmlpull.v1.**
-keep class org.xmlpull.* { *; }
#retRofit
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# Orm
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder.* { *; }
-keepclassmembers class * {
native <methods>;
}
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn okhttp3.**
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**
# com.github.siyamed:android-shape-imageview
-dontwarn android.support.v7.**
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.*{ *; }
-dontwarn org.xmlpull.v1.**
-dontwarn uk.co.senab.photoview.**
#Image Cropper
-keep class androidx.appcompat.widget.* { *; }
# Keep source file names, line numbers, and Parse class/method names for easier debugging
-keepattributes SourceFile,LineNumberTable
-keepnames class com.parse.* { *; }
# Required for Parse
-keepattributes *Annotation*
-keepattributes Signature
-dontwarn com.squareup.**
-dontwarn okio.**
-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {
native <methods>;
}