3

當運行我的即時應用程序,我得到以下inflateException:即時APP InflateException

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xfzj.instantappdemo/com.xfzj.instantappdemo.feature.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.design.widget.AppBarLayout 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                      Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.design.widget.AppBarLayout 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:539) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                      at com.xfzj.instantappdemo.feature.MainActivity.onCreate(MainActivity.java:17) 
                      at android.app.Activity.performCreate(Activity.java:6237) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
</pre> 

這裏是我的layout.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.xfzj.instantappdemo2.feature.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    app:srcCompat="@android:drawable/ic_dialog_email" /> 
</LinearLayout> 

這裏是我的功能模塊的build.gradle文件:

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    implementation project(':base') 
    implementation 'com.android.support:appcompat-v7:25.4.0' 
    testImplementation 'junit:junit:4.12' 
    implementation 'com.android.support:design:25.4.0' 
} 

如果我運行安裝的應用程序,它會成功。

com.android.support:design:25.4.0與即時應用程序不兼容?

回答

0

由於兩個瞬間,並安裝應用程序分享設計庫,依賴

implementation 'com.android.support:appcompat-v7:25.4.0 

應該是基本特徵build.gradle文件,而不是在installed

如果您想將其包含在某些非基本功能中,請確保即時和安裝的build.gradle文件都包含此功能。

+0

它在功能build.gradle,不在安裝。 – user6310522

+0

即時和安裝都具有'build.gradle'中的功能依賴關係嗎? – mol

+0

是的,他們都具有功能依賴。我反編譯即時應用程序的代碼,找到它的android.support.v7和設計等。 – user6310522

1

com.android.support:design:25.4.0受Instant Apps支持。問題在於功能模塊之間的appcompat設計支持庫的重複依賴項。通常,因爲這些庫是常見的跨功能,它們將被包括在基本功能模塊的build.gradle文件(建立一個默認的即時應用項目,例如在Android工作室):

dependencies { 
    application project(':app') 
    feature project(':feature') 
    api 'com.android.support:appcompat-v7:25.4.0' 
    api 'com.android.support.constraint:constraint-layout:1.0.2' 
    api 'com.android.support:design:25.4.0' 
} 

由於其他功能模塊具有基本的依賴關係功能模塊,它們本身不應包含這些庫。該功能模塊的build.gradle只需包含:

dependencies { 
    ... 
    implementation project(':base') 
    ... 
} 

換句話說,基本的功能模塊中定義的所有庫可用於其他功能,他們不應該被重新添加作爲一個依賴。

相關問題