Could not find any version that matches com.android.support:appcompat-v7:29.+.
具体报错如下:
Could not find any version that matches com.android.support:appcompat-v7:29.+.
Versions that do not match:
- 26.0.0-alpha1
- 25.3.1
- 25.3.0
- 25.2.0
- 25.1.1
- + 50 more
Required by:
project :app
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
如果你也有类似的问题,那你可能也踏上了AndroidX之路:
- 随着Android 9.0(API级别28)的发布,有一个名为AndroidX的支持库的新版本出现,而29没有对应的支持库,也就是说
com.android.support:appcompat-v7:29.+.
根本不存在! - 原因找到了,那该如何解决问题呢?两条路:第一条,在所有新项目中使用AndroidX库,第二条,使用支持库,即API版本为27及更早版本,将继续在Google Maven上提供。但是,所有新的库开发都将在AndroidX库中进行。AndroidX是趋势,所以选了第一条。
- 使用 Android Studio 迁移现有项目,通过从菜单栏中依次选择 Refactor > Migrate to AndroidX,快速迁移现有项目以使用 AndroidX。之后发现错误消失了,但MainActivity中依旧报错,v7报红,原来刚刚自动快速迁移时编译器并没有全部完成,有些东西还得自己改,将
android.support.v7.app.AppCompatActivity
改为androidx.appcompat.app.AppCompatActivity
。顺利解决。 - 再次模拟器运行程序,程序崩溃,/吐血/,查看日志,说明如下:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication4/com.example.myapplication4.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
将implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
换成implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
即可,两个版本有区别。再次运行,顺利完成。
参考资料:
6. AndroidX 概览
7. 迁移到 AndroidX
8. Support Library Packages