版本2.2(级别8)上的Android支持库ActionBar NullPointerException - 与preferences.xml冲突

时间:2014-01-07 15:50:05

标签: android maven android-support-library android-maven-plugin

我正在使用v7支持库在Android 2.x上显示ActionBar。

当我在IDE(Intellij IDEA)中将应用程序部署到设备时,应用程序运行正常。

当我使用maven构建和打包要部署到Play商店的应用程序时,我发现当我在设备上安装并运行打包应用程序并且应用程序崩溃时,我收到以下异常。 (它也在v8模拟器上失败了)。它在android v4.3的两个场景中都能正常工作。

知道为什么在使用maven构建时会崩溃?

01-07 15:05:22.671      937-937/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.triopsis.as.mobile.android/com.triopsis.as.mobile.android.activity.MainMenuActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.internal.widget.ActionBarView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.internal.widget.ActionBarView
        at android.view.LayoutInflater.createView(LayoutInflater.java:513)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:677)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:614)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
        at android.app.Activity.setContentView(Activity.java:1647)
        at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:180)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:134)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
        at com.triopsis.as.mobile.android.activity.MainMenuActivity.onCreate(MainMenuActivity.java:43)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.reflect.InvocationTargetException
        at android.support.v7.internal.widget.ActionBarView.<init>(ActionBarView.java:218)
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
        at android.view.LayoutInflater.createView(LayoutInflater.java:500)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:677)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:614)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
        at android.app.Activity.setContentView(Activity.java:1647)
        at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:180)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:134)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
        at com.triopsis.as.mobile.android.activity.MainMenuActivity.onCreate(MainMenuActivity.java:43)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
        at android.support.v7.internal.widget.ActionBarView$HomeView.onFinishInflate(ActionBarView.java:1301)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.support.v7.internal.widget.ActionBarView.<init>(ActionBarView.java:218)
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
        at android.view.LayoutInflater.createView(LayoutInflater.java:500)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:677)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:614)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
        at android.app.Activity.setContentView(Activity.java:1647)
        at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:180)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:134)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
        at com.triopsis.as.mobile.android.activity.MainMenuActivity.onCreate(MainMenuActivity.java:43)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)

我在maven中有以下依赖项:

<dependencies>
    <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <version>4.0_r3</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>android.support</groupId>
        <artifactId>compatibility-v7-appcompat</artifactId>
        <version>19.0.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>android.support</groupId>
        <artifactId>compatibility-v7-appcompat</artifactId>
        <version>19.0.1</version>
        <type>apklib</type>
    </dependency>
    <dependency>
        <groupId>android.support</groupId>
        <artifactId>compatibility-v13</artifactId>
        <version>19.0.1</version>
        <type>jar</type>
    </dependency>
</dependencies>

并配置以下maven-android-plugin:

<build>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.8.2</version>
            <configuration>
                <sdk>
                    <platform>14</platform>
                </sdk>
            </configuration>
            <extensions>true</extensions>
        </plugin>
    </plugins>
</build>

更新

它花了一段时间,但我发现当我有带有PreferenceScreen设置的res / xml / preferences.xml文件时,它会导致此崩溃。如果我删除此文件,它不会崩溃。 任何人都知道为什么会导致这个问题?

1 个答案:

答案 0 :(得分:1)

您是否绝对需要android-maven-plugin版本3.8.2的功能?这似乎很烦人。

android-maven-plugin从版本3.8.0更新为3.8.2后,我们的项目中出现了类似的问题。

回到版本3.8.0解决了这个问题。

<强>症状:
我们的结论是问题在于apklib的链接,引用的所有资源(布局,drawables ......)似乎都是不对齐的。例如,显示布局或可绘制而不是另一个。当访问布局中缺少的引用/ id时,应用程序崩溃(由于加载了错误的布局,引用不存在)。

请参阅问题http://code.google.com/p/maven-android-plugin/issues/detail?id=441