我今天早上使用新的SDK升级了我的Gradle:
// https://developer.android.com/studio/build/multidex.html
implementation 'com.android.support:multidex:1.0.3'
// https://developer.android.com/topic/libraries/support-library/revisions.html
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:customtabs:27.1.0'
implementation 'com.android.support:gridlayout-v7:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:support-v13:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:exifinterface:27.1.0'
不幸的是,现在我的第一个Activity启动时出现了崩溃。此活动没有布局。它在SDK升级之前完美运行......
03-06 10:20:33.117 18722-18722/com.xxx.dev E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.azeoo.dev, PID: 18722
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.dev/com.xxx.ui.intro.WelcomeActivity}: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class LinearLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class LinearLayout
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class LinearLayout
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
at android.content.res.TypedArray.getString(TypedArray.java:202)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1006)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.android.internal.policy.DecorView.onResourcesLoaded(DecorView.java:1776)
at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2613)
at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2686)
at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2049)
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.initWindowDecorActionBar(AppCompatDelegateImplV9.java:175)
at android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:145)
at android.support.v7.app.AppCompatActivity.getSupportActionBar(AppCompatActivity.java:109)
at com.xxx.ui.BaseActivity.onCreate(BaseActivity.java:759)
at com.xxx.ui.intro.WelcomeActivity.onCreate(WelcomeActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
非常感谢你们的支持!
答案 0 :(得分:2)
删除
如果您要升级到buildToolsVersion
,请从应用级Gradle文件 27.1.0
。所以,如果你把
buildToolsVersion 27.0.2
或buildToolsVersion 27.0.3
可能存在冲突原因buildToolsVersion 27.1.0
尚未发布。
所以,删除
buildToolsVersion x.x.x
可能会有所帮助!!
修改1
即使删除buildToolsVersion可能会有效,但我建议您坚持使用27.0.2
,因为27.1.0
导致某些意外崩溃并且有一些bugs
。
其中之一是: -
即便谷歌也已宣布(在GOOGLE ISSUE TRACKER中)。所以,伙计们最好坚持27.0.2
,直到发布固定版和稳定版。