Android Studio 错误Error:(16, 13) Failed to resolve: com.android.support:support-v4:15.+ android.vi

错误1:
Error:(16, 13) Failed to resolve: com.android.support:support-v4:15.+
<a href="install.m2.repo">Install Repository and sync project</a><br><a href="openFile:D:/UserData/scxh/Desktop/call/call/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>


解决办法:
方法一:
打开build.gradle文件,看dependencies{   }里面是不是有compile 'com.android.support:support-v4:15.+'和compile files('libs/android-support-v4.jar')两个,如果有就删除没找到的那个,比如上面的例子就该删除compile 'com.android.support:support-v4:15.+'
方法二:在android sdk manager上把 android library support的库也都装上,重新build。


错误2:
android.view.InflateException: Binary XML file line #7: Error inflating class fragment
关键log:
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Must specify unique android:id, android:tag, or have a parent with an id for fragment_demo.fragment.FragmentTwo

解决办法:看报错类对应布局里的Fragment 是否定义了id属性。把id属性加上。XML布局文件中Fragment标签必须设置id属性。




注意事项:
Android SDK 6.0的Fragment回调方法中的android.view.InflateException:参数为Content很有可能不会执行的哟。其他都没错的话就看看这个方法执行没有吧。
    @Override
    public void onAttach(Content content) {
        super.onAttach(content);
        Log.d("test", "onAttach:00000000000000000000000 ");
        Mylog.d("onAttach-------------------------");
    }


若没执行还是用SDK6.0之前用的onAttach(Activity activity)参数为Activity回调方法吧。
 @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        Log.d("test", "onAttach:00000000000000000000000 ");
        Mylog.d("onAttach-------------------------");
    }
这个问题可能是由于你的项目中使用了过时的 Android Support Library 而导致的。在最新版本的 Android Gradle 插件中,Google 已经将 Android Support Library 替换为 AndroidX。因此,你需要将你的项目迁移到 AndroidX。 要迁移到 AndroidX,你可以使用 Android Studio 中的 Refactor 工具。具体步骤如下: 1. 打开你的项目,在菜单栏中选择 Refactor -> Migrate to AndroidX。 2. 在弹出的对话框中,选择要迁移的项目和模块,然后点击 Refactor。 3. Android Studio 将会自动为你的项目更改所有依赖项和类引用,以使它们指向新的 AndroidX 库。 4. 如果 Refactor 过程中出现任何问题,你可以手动更改你的 build.gradle 文件,以使用 AndroidX 库。在 build.gradle 文件中添加以下代码: ``` android { ... defaultConfig { ... // 增加以下两行 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" android.useAndroidX=true } // 增加以下两行 configurations.all { resolutionStrategy { force 'com.android.support:support-v4:28.0.0' // 使用 28.0.0 版本的 support-v4 库 } } } // 移除以下两行 // implementation 'com.android.support:support-v4:28.0.0' // implementation 'com.android.support:appcompat-v7:28.0.0' // 增加以下两行 implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' ``` 5. 最后,点击菜单栏中的 Build -> Clean Project,等待清除完成后再点击 Build -> Rebuild Project,重新构建你的项目。 如果你还遇到其他问题,请参考 Google 的官方文档:[Migrating to AndroidX](https://developer.android.com/jetpack/androidx/migrate)。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值