我有一个谷歌服务,片段等应用程序。这是一个gradle项目 调试版本通常从Android-on GT-N7100和其他设备上运行。 使用命令行生成的重新分析版本在各种设备上运行正常,但在使用膨胀布局时,在带有空指针异常的GT-N7100上崩溃。 GT-N7100已经植根了固件,android 4.4.2
Fragment中的代码继承自android.app.Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Context context = inflater.getContext();
mRoot = (ViewGroup) inflater.inflate(R.layout.fragment_ecg_detection, container, false);
mRoot.findViewById(R.id.deviceConnectedBtn).setOnClickListener(this);
mRoot.findViewById(R.id.instructionsBtn).setOnClickListener(this);
.......
return mRoot;
}
它在行
上抛出NullPointerExceptionmRoot.findViewById(R.id.deviceConnectedBtn).setOnClickListener(this);
资源R.layout.fragment_ecg_detection只声明一次:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@drawable/bg_instruction"
tools:context="ru.nordavind.ecgdongle.fragment.StickDetectionFragment">
....
<LinearLayout
android:layout_width="320dp"
android:layout_height="48dp"
android:background="@drawable/btn_white"
android:elevation="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:id="@+id/instructionsBtn"
android:clickable="true"
android:layout_above="@+id/deviceConnectedBtn"
android:layout_centerHorizontal="true"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/instructions"
android:gravity="left"
android:layout_marginLeft="4dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_forward_600"/>
</LinearLayout>
....
</RelativeLayout>
gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
repositories {
mavenLocal()
jcenter()
}
android {
compileSdkVersion 22
buildToolsVersion '23.0.3'
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 47
versionName "1.2." + versionCode
}
applicationVariants.matching(
{ it.buildType.name == android.buildTypes.release.name }
).all { variant ->
def flavor = variant.productFlavors.get(0)
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"${flavor.name}-release-${variant.versionName}.apk")
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
signingConfigs {
releaseConfig {
storeFile file("...")
storePassword "..."
keyAlias "..."
keyPassword "..."
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.releaseConfig
/*
due to bug
https://code.google.com/p/analytics-issues/issues/detail?id=733
*/
lintOptions { disable 'MissingTranslation' }
}
debug {
signingConfig signingConfigs.releaseConfig
}
}
testOptions {
unitTests.returnDefaultValues = true
}
productFlavors {
...
EcgDongle {
applicationId '.....'
versionCode 41
versionName "1." + (versionCode - 34) + ".2"
copy {
from "src/EcgDongle"
include "google-services.json"
into "."
}
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
testCompile 'junit:junit:4.12'
androidTestCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile('org.robolectric:robolectric:3.0-rc3') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile 'me.relex:circleindicator:1.1.6@aar'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'com.opencsv:opencsv:3.6'
compile 'ch.acra:acra:4.6.1'
}
异常:
java.lang.RuntimeException: Unable to resume activity {ru.nordavind.ecgdongle/ru.nordavind.ecgdongle.MainActivityEcgStick}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3076)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3105)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at ru.nordavind.ecgdongle.fragment.StickDetectionFragment.onCreateView(StickDetectionFragment.java:56)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1453)
at android.app.Activity.performResume(Activity.java:5541)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3066)
... 12 more
之前,我收到消息:
06-23 16:50:27.266 I/dalvikvm(30277): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.zze.zzi
06-23 16:50:27.266 W/dalvikvm(30277): VFY: unable to resolve virtual method 588: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
06-23 16:50:27.266 D/dalvikvm(30277): VFY: replacing opcode 0x6e at 0x000b
06-23 16:50:27.311 I/GMPM (30277): App measurement is starting up, version: 8487
06-23 16:50:27.311 I/GMPM (30277): To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
06-23 16:50:27.336 E/GMPM (30277): GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
06-23 16:50:27.336 E/GMPM (30277): Scheduler not set. Not logging error/warn.
06-23 16:50:27.391 E/GMPM (30277): Uploading is not possible. App measurement disabled
06-23 16:50:27.681 W/dalvikvm(30277): VFY: unable to find class referenced in signature (Landroid/os/PersistableBundle;)
06-23 16:50:27.681 I/dalvikvm(30277): Could not find method android.support.v7.app.AppCompatActivity.onRestoreInstanceState, referenced from method ru.nordavind.ecgdongle.MainActivityEcgStick.onRestoreInstanceState
06-23 16:50:27.681 W/dalvikvm(30277): VFY: unable to resolve virtual method 11841: Landroid/support/v7/app/AppCompatActivity;.onRestoreInstanceState (Landroid/os/Bundle;Landroid/os/PersistableBundle;)V
06-23 16:50:27.681 D/dalvikvm(30277): VFY: replacing opcode 0x6f at 0x0000
06-23 16:50:27.751 W/dalvikvm(30277): No implementation found for native Ldalvik/system/VMRuntime;.pauseGc:(Ljava/lang/String;)I
06-23 16:50:27.751 E/ActivityThread(30277): Pause GC
06-23 16:50:27.751 E/ActivityThread(30277): java.lang.reflect.InvocationTargetException
06-23 16:50:27.751 E/ActivityThread(30277): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 16:50:27.751 E/ActivityThread(30277): at java.lang.reflect.Method.invoke(Method.java:515)
06-23 16:50:27.751 E/ActivityThread(30277): at android.app.ActivityThread.pauseGC(ActivityThread.java:5525)
06-23 16:50:27.751 E/ActivityThread(30277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
06-23 16:50:27.751 E/ActivityThread(30277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
06-23 16:50:27.751 E/ActivityThread(30277): at android.app.ActivityThread.access$900(ActivityThread.java:175)
06-23 16:50:27.751 E/ActivityThread(30277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
06-23 16:50:27.751 E/ActivityThread(30277): at android.os.Handler.dispatchMessage(Handler.java:102)
06-23 16:50:27.751 E/ActivityThread(30277): at android.os.Looper.loop(Looper.java:146)
06-23 16:50:27.751 E/ActivityThread(30277): at android.app.ActivityThread.main(ActivityThread.java:5602)
06-23 16:50:27.751 E/ActivityThread(30277): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 16:50:27.751 E/ActivityThread(30277): at java.lang.reflect.Method.invoke(Method.java:515)
06-23 16:50:27.751 E/ActivityThread(30277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
06-23 16:50:27.751 E/ActivityThread(30277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
06-23 16:50:27.751 E/ActivityThread(30277): at dalvik.system.NativeStart.main(Native Method)
06-23 16:50:27.751 E/ActivityThread(30277): Caused by: java.lang.UnsatisfiedLinkError: Native method not found: dalvik.system.VMRuntime.pauseGc:(Ljava/lang/String;)I
06-23 16:50:27.751 E/ActivityThread(30277): at dalvik.system.VMRuntime.pauseGc(Native Method)
06-23 16:50:27.751 E/ActivityThread(30277): ... 15 more
06-23 16:50:27.786 D/dalvikvm(30277): GC_CONCURRENT freed 310K, 14% free 8086K/9368K, paused 3ms+3ms, total 21ms
06-23 16:50:27.906 I/dalvikvm(30277): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
06-23 16:50:27.906 W/dalvikvm(30277): VFY: unable to resolve virtual method 666: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
06-23 16:50:27.906 D/dalvikvm(30277): VFY: replacing opcode 0x6e at 0x0002
06-23 16:50:27.906 I/dalvikvm(30277): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
06-23 16:50:27.906 W/dalvikvm(30277): VFY: unable to resolve virtual method 688: Landroid/content/res/TypedArray;.getType (I)I
06-23 16:50:27.906 D/dalvikvm(30277): VFY: replacing opcode 0x6e at 0x0002
06-23 16:50:27.931 D/dalvikvm(30277): GC_CONCURRENT freed 384K, 15% free 8138K/9496K, paused 3ms+1ms, total 22ms
包括
GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
它看起来搞砸了资源。 该怎么办?