使用Blurkit库,我在onCreate中崩溃了。我使用Android版本24,不确定是否重要。下面是部分堆栈跟踪。我错过了什么?提前谢谢!
的build.gradle
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
...
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
}
}
dependencies {
...
compile 'com.wonderkiln:blurkit:1.0.0'
}
崩溃:
JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.NoSuchMethodError: no static or non-static method "Landroid/support/v8/renderscript/RenderScript;.nDeviceDestroy(J)V"
at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String) (Runtime.java:-2)
at java.lang.String java.lang.Runtime.doLoad(java.lang.String, java.lang.ClassLoader) (Runtime.java:435)
at void java.lang.Runtime.loadLibrary(java.lang.String, java.lang.ClassLoader) (Runtime.java:370)
at void java.lang.System.loadLibrary(java.lang.String) (System.java:1076)
at android.support.v8.renderscript.RenderScript android.support.v8.renderscript.RenderScript.internalCreate(android.content.Context, int, android.support.v8.renderscript.RenderScript$ContextType, int) (RenderScript.java:1385)
at android.support.v8.renderscript.RenderScript android.support.v8.renderscript.RenderScript.create(android.content.Context, int, android.support.v8.renderscript.RenderScript$ContextType, int) (RenderScript.java:1576)
at android.support.v8.renderscript.RenderScript android.support.v8.renderscript.RenderScript.create(android.content.Context, android.support.v8.renderscript.RenderScript$ContextType, int) (RenderScript.java:1526)
at android.support.v8.renderscript.RenderScript android.support.v8.renderscript.RenderScript.create(android.content.Context, android.support.v8.renderscript.RenderScript$ContextType) (RenderScript.java:1502)
at android.support.v8.renderscript.RenderScript android.support.v8.renderscript.RenderScript.create(android.content.Context) (RenderScript.java:1489)
at void com.wonderkiln.blurkit.BlurKit.init(android.content.Context) (BlurKit.java:25)
at void com.wonderkiln.blurkit.BlurLayout.<init>(android.content.Context, android.util.AttributeSet) (BlurLayout.java:53)
at java.lang.Object java.lang.reflect.Constructor.newInstance!(java.lang.Object[]) (Constructor.java:-2)
at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:619)
at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:764)
at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:704)
at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:835)
at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:798)
at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:838)
at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:798)
at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
at void com.android.internal.policy.PhoneWindow.setContentView(int) (PhoneWindow.java:393)
at void android.app.Activity.setContentView(int) (Activity.java:2172)
at void <Activity>.onCreate(android.os.Bundle) (ACActivity.java:67)
答案 0 :(得分:2)
我想通了,这是一个Proguard问题。只需将以下内容添加到您的proguard规则中:
-dontwarn android.support.v8.renderscript.*
-keepclassmembers class android.support.v8.renderscript.RenderScript {
native *** rsn*(...);
native *** n*(...);
}
答案 1 :(得分:1)
如果在迁移到AndroidX后遇到此问题,则需要调整ProGuard规则,如下所示:
-dontwarn androidx.renderscript.*
-keepclassmembers class androidx.renderscript.RenderScript {
native *** rsn*(...);
native *** n*(...);
}