棒棒糖为SupportMapFragment投掷错误签名

时间:2014-11-18 19:35:44

标签: android crash google-maps-android-api-2 android-5.0-lollipop supportmapfragment

我有一个Android应用程序,通过SupportMapFragment显示地图。该应用程序在过去几个月运行良好,直到最近我将手机从4.4.4升级到5.0(通过官方OTA更新)。现在应用程序崩溃,我得到以下堆栈跟踪:

11-18 12:51:49.699  12594-12594/com.foo.bar E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.foo.bar, PID: 12594
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.foo.bar/com.foo.bar.CallActivity}: android.view.InflateException: Binary XML file line #89: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: android.view.InflateException: Binary XML file line #89: Error inflating class fragment
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
            at android.app.Activity.setContentView(Activity.java:2144)
            at com.foo.bar.CallActivity.onCreate(CallActivity.java:89)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.SecurityException: Incorrect signature
            at org.apache.harmony.security.utils.JarUtils.verifySignature(JarUtils.java:223)
            at java.util.jar.JarVerifier.verifyCertificate(JarVerifier.java:294)
            at java.util.jar.JarVerifier.readCertificates(JarVerifier.java:268)
            at java.util.jar.JarFile.getInputStream(JarFile.java:380)
            at libcore.net.url.JarURLConnectionImpl.getInputStream(JarURLConnectionImpl.java:222)
            at java.net.URL.openStream(URL.java:470)
            at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:444)
            at java.lang.Class.getResourceAsStream(Class.java:1334)
            at com.google.l.a.a.a.a(Unknown Source)
            at com.google.l.a.a.a.a(Unknown Source)
            at com.google.maps.api.android.lib6.b.e.<init>(Unknown Source)
            at com.google.maps.api.android.lib6.b.e.<init>(Unknown Source)
            at com.google.maps.api.android.lib6.b.e.a(Unknown Source)
            at com.google.maps.api.android.lib6.c.dm.a(Unknown Source)
            at com.google.maps.api.android.lib6.c.dw.a(Unknown Source)
            at com.google.maps.api.android.lib6.c.v.a(Unknown Source)
            at com.google.maps.api.android.lib6.c.u.a(Unknown Source)
            at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
            at android.os.Binder.transact(Binder.java:380)
            at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
            at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
            at com.google.android.gms.dynamic.a$4.b(Unknown Source)
            at com.google.android.gms.dynamic.a.a(Unknown Source)
            at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
            at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:920)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
            at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1206)
            at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2159)
            at android.support.v4.app.FragmentActivity.onCreateVie

这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/myLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".CallActivity"
    android:orientation="vertical"
    android:background="#FFFFFF" >

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>

这是我的gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.foo.bar"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 126
        versionName "1.0.126"
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:21.0.+'
    compile 'com.google.android.gms:play-services:6.1.71'
    compile fileTree(dir: 'libs', include: '*.jar')
}

以下是活动的相关部分:

public class CallActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call); // this is line 89 (the line referenced in the stack trace)
        ...

相同的应用程序仍然适用于另一部旧版Android的手机。如果我从布局中删除片段,它会在没有崩溃的情况下运行5.0(当然没有地图),所以我相当确定它是导致问题。

还有其他人见过这样的事吗?什么尝试的想法?

3 个答案:

答案 0 :(得分:3)

尝试更改

static {
    Security.addProvider(new BouncyCastleProvider());
}

static {
    Security.insertProviderAt(new BouncyCastleProvider(), 1);
}

另见 https://github.com/rtyley/spongycastle-old/issues/10

答案 1 :(得分:0)

我明白了。它与spongycastle有关。我的应用程序类中有以下内容:

static {
    Security.addProvider(new BouncyCastleProvider());
}

一旦我注意到该块,它就开始工作了。

答案 2 :(得分:0)

创建Google地图视图时删除BouncyCastle / SpongyCastle提供程序。 然后在销毁Google地图视图时再次添加。

创建从SupportMapFragment继承的片段。 覆盖onCreateView和onDestroyView。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (Build.VERSION.RELEASE.equals("5.0"))
    {
        Security.removeProvider("SC");
    }
    return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onDestroyView() {
    if (Build.VERSION.RELEASE.equals("5.0"))
    {
        Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
    }
    super.onDestroyView();
}

在布局xml中使用此继承的片段而不是SuuportMapFragment。