RN 0.55.4
Gradle: 2.2.3
Android上有一个问题。我们更新了一些node_modules,并对0.55版做出了本机反应,一切看起来都还不错,但是当我们将此新版本发布到Google Beta中时,然后下载它进行测试,该应用始终在首次运行时崩溃。我们再次运行它,一切正常,应用程序正常运行。而且我们不知道怎么了 从fabric.io得到的错误仅在从游戏中下载该应用程序时发生一次。
Fatal Exception: java.lang.ExceptionInInitializerError
at tv.dailyme.android.util.ServerConfig.getUrlRegisterWithoutPhonenr(Unknown Source)
at tv.dailyme.android.util.UserRegistration.setInstallReferrer(Unknown Source)
at tv.dailyme.android.core.receiver.InstallReceiver.onReceive(Unknown Source)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3102)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:6459)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:938)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
这也同时发生
Fatal Exception: java.lang.RuntimeException: Unable to start receiver tv.dailyme.android.core.receiver.Autostart: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.sqlite.SQLiteDatabase android.content.Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase$CursorFactory, android.database.DatabaseErrorHandler)' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3116)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:6459)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:938)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
我认为我们的gradle设置有问题
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
// NOTE LSA: if you change this value, You will have to change same value in "Project: Awe" => build.gradle
def googlePlayServiceVersion = '11.0.4'
android {
compileSdkVersion 26
buildToolsVersion "26.0.3"
defaultConfig {
applicationId "com.awesome.app"
minSdkVersion 17
targetSdkVersion 25
versionCode 1007138
versionName "6.6.0"
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
jackOptions {
enabled true
}
vectorDrawables.useSupportLibrary = true
ndk {
abiFilters "armeabi-v7a", "x86"
}
multiDexEnabled true
manifestPlaceholders = [manifestApplicationId: "${applicationId}",
onesignal_app_id: "7xxxxxxxxxxxxxxxxxxxDDc",
onesignal_google_project_number: "9999999999"]
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dexOptions {
javaMaxHeapSize "4g"
}
lintOptions {
abortOnError false
}
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
debug {
manifestPlaceholders = [excludeSystemAlertWindowPermission: "false"]
}
release {
manifestPlaceholders = [excludeSystemAlertWindowPermission: "true"]
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice.txt'
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
exclude 'META-INF/DEPENDENCIES'
exclude 'error_prone/Annotations.gwt.xml'
exclude 'third_party/java_src/error_prone/project/annotations/Annotations.gwt.xml'
exclude 'third_party/java_src/error_prone/project/annotations/Google_internal.gwt.xml'
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a": 1, "x86": 2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile project(':react-native-social-share')
compile project(':react-native-device-info')
compile project(':react-native-fetch-blob')
compile project(':react-native-blur')
compile project(':react-native-admob')
compile project(':react-native-vector-icons')
compile project(':react-native-orientation')
compile project(':react-native-spinkit')
compile project(':react-native-i18n')
compile project(':react-native-share')
compile project(':react-native-cookies')
compile fileTree(dir: "libs", include: ["*.jar"])
// TODO LSA when we upgrade RN to 0.56 and gradle 3 we will have to remove all FORCE = TRUE and update com.android.support libs
compile "com.android.support:appcompat-v7:26.1.0"
compile "com.android.support:palette-v7:26.1.0"
compile("com.facebook.react:react-native:0.55.4") { force = true }
compile project(':react-native-onesignal')
compile 'tv.nexx:nexxplay-android:3.2.1'
compile(name: 'library-release', ext: 'aar')
compile('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'stax', module: 'stax-api'
exclude group: 'xpp3', module: 'xpp3'
}
compile project(":react-native-device-info")
compile fileTree(dir: "node_modules/react-native-device-info/android/libs", include: ["*.jar"])
compile 'org.apache.mina:mina-statemachine:2.0.9'
compile("com.google.android.gms:play-services-analytics:${googlePlayServiceVersion}") {
force = true;
}
compile("com.google.android.gms:play-services-ads:${googlePlayServiceVersion}") {
force = true;
}
compile("com.google.android.gms:play-services-gcm:${googlePlayServiceVersion}") {
force = true;
}
compile("com.google.android.gms:play-services-location:${googlePlayServiceVersion}") {
force = true;
}
compile("com.google.android.gms:play-services-base:${googlePlayServiceVersion}") {
force = true;
}
compile(name: 'infonlinelib_1.1.5.1', ext: 'aar')
compile(name: 'IRSurveyLib-1.4.0', ext:'aar')
compile 'com.android.support:multidex:1.0.1'
compile group: 'com.alibaba', name: 'fastjson', version: '1.1.25'
compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
transitive = true;
}
compile project(':react-native-fabric')
compile 'com.alibaba:fastjson:1.1.25'
compile 'com.adjust.sdk:adjust-android:4.7.0'
compile 'ad.nugg.android:sdk:3.2.2'
}
我们的ProGuard应用规则
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Disabling obfuscation is useful if you collect stack traces from production crashes
# (unless you are using a system that supports de-obfuscate the stack traces).
-dontobfuscate
# React Native
# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.proguard.annotations.DoNotStrip *;
@com.facebook.common.internal.DoNotStrip *;
}
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
void set*(***);
*** get*();
}
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
-dontwarn com.facebook.react.**
# TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
-dontwarn android.text.StaticLayout
# okhttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
# okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**
#GAID
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keepattributes EnclosingMethod
-keepattributes InnerClasses
-dontwarn InnerClasses
-dontoptimize
-keep class com.newrelic.** { *; }
-dontwarn com.newrelic.**
-keepattributes Exceptions, Signature, InnerClasses
答案 0 :(得分:0)
致命异常:java.lang.RuntimeException:无法启动接收器tv.dailyme.android.core.receiver.Autostart:java.lang。 NullPointerException :
尝试调用虚拟方法'android.database.sqlite.SQLiteDatabase android.content.Context。 openOrCreateDatabase (java.lang.String,int,android.database.sqlite.SQLiteDatabase $ CursorFactory,android .database.DatabaseErrorHandler)'
关于空对象引用
它出现,好像您的ProGuard配置可能不足以不混淆某些内容。
您可以在类!= null
中添加一个tv.dailyme.android.core.receiver.Autostart
检查,以便至少不产生该NPE
的抛出。似乎需要改进ProGuard -keep
规则。