Java Android 4.4 SDK 更新后 android-support-v7-appcombat jar 不匹配和应用程序崩溃

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19989116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:05:46  来源:igfitidea点击:

android-support-v7-appcombat jar mismatch and app crashing after Android 4.4 SDK update

javaandroid-support-libraryandroid-4.4-kitkatandroid-appcompat

提问by MSIslam

I have been successfully using android-support-v7-appcompat library for last few months in my app to support action bar in older devices. Recently I have downloaded the Android 4.4(kitkat) updates with system image and SDK platform from the SDK Manager. I also added targetSdkVersion to "19" in manifest file. But my project was showing error as 'android-support-v7-appcompat jar mismatch. Fix your dependaecies.' Then I added the jar from /extras/android/support/.... to the project as an external jar using build path menu > add external jar. Now there is no error in the project and android-support-v7-appcompat.jar & android-support0v4.jar file is showing twice under 'Referenced Libraries' folder and also once under 'libs' folder. The project is not showing error and running, but crashing in different activities.

过去几个月我一直在我的应用程序中成功使用 android-support-v7-appcompat 库来支持旧设备中的操作栏。最近我从 SDK Manager 下载了带有系统映像和 SDK 平台的 Android 4.4(kitkat) 更新。我还在清单文件中将 targetSdkVersion 添加到“19”。但是我的项目显示错误为“android-support-v7-appcompat jar 不匹配”。修复你的依赖。然后我使用构建路径菜单 > 添加外部 jar 将 /extras/android/support/.... 中的 jar 作为外部 jar 添加到项目中。现在项目中没有错误,android-support-v7-appcompat.jar 和 android-support0v4.jar 文件在“Referenced Libraries”文件夹下显示两次,在“libs”文件夹下也显示一次。该项目未显示错误并正在运行,

Previously I imported the android-support-v7-appcombat library as an external project in the workplace. I can see error in that project. Please suggest what should I do now. Also, android-support-v7-appcompat.jar umder Android Dependencies in Java Build Path showing error.

之前我在工作场所导入了android-support-v7-appcombat库作为外部项目。我可以看到该项目中的错误。请建议我现在应该做什么。此外,android-support-v7-appcompat.jar umder Android Dependencies in Java Build Path 显示错误。

The error I see is:

我看到的错误是:

Found 2 versions of android-support-v7-appcompat.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.

Versions found are:

Path: C:\<project hierarchy>\libs\android-support-v7-appcompat.jar

Path: C:\Users\....\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar

 Jar mismatch! Fix your dependencies

After getting idea from different forum, I removed all the android-support-v7-appcompat libraries from different places, and imported android-v7 support library again in the project. Still it's showing error. Should I also delete android-support-v4 libraries from buildpath and libs/private librariry/referenced library folders?

从不同的论坛得到想法后,我从不同的地方删除了所有的 android-support-v7-appcompat 库,并在项目中再次导入了 android-v7 支持库。仍然显示错误。我还应该从 buildpath 和 libs/private library/referenced library 文件夹中删除 android-support-v4 库吗?

回答by Vivek Soneja

This error occurs when there are multiple and different instances of the same library are found in the same project, or libraries used by it. A very simple way to resolve this is use the common lib at both the places. To do so:

当在同一个项目或它使用的库中发现同一个库的多个不同实例时,会发生此错误。解决这个问题的一个非常简单的方法是在两个地方使用公共库。这样做:

Just copy your C:\Users....\AppData\Local\Android\android-studio\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar and paste it in your libs folder, replace the old one with this. Clean the project, and it shall compile now..

只需复制您的 C:\Users....\AppData\Local\Android\android-studio\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar 并将其粘贴到您的libs 文件夹,用这个替换旧的。清理项目,它现在应该编译..

Edit 1:Basically the idea is if you are using the same libraries, it shall be the common jar, or the same jar. In your case if you are using the appv7 as an external project, please go to libs folder of your project copy android-support-v4.jar, and paste into the libs of android-support-v7-appcompat project.

编辑 1:基本上这个想法是如果你使用相同的库,它应该是普通的 jar,或者同一个 jar。在您的情况下,如果您使用 appv7 作为外部项目,请到您项目的 libs 文件夹中复制 android-support-v4.jar,并粘贴到 android-support-v7-appcompat 项目的 libs 中。

Also, make sure if there are other external jars or support libraries used by you, they shall be the similar jars in all the projects you are using.

另外,请确保您是否使用了其他外部 jar 或支持库,它们应该是您正在使用的所有项目中的类似 jar。

I hope it helps!

我希望它有帮助!

回答by MSIslam

I have actually figured out the solution by trying different options suggested from different forum. I had manually change the android-support-v7-appcompat project's(which was added as an external project) project.properties file and had to set 'target=android-19'.

我实际上已经通过尝试不同论坛建议的不同选项找到了解决方案。我手动更改了 android-support-v7-appcompat 项目(作为外部项目添加)的 project.properties 文件,并且必须设置“target=android-19”。

回答by Hong

I had exactly the same problem after installing all the updates mentioned in the question. I am sure there are different ways to solve this problem. Here is the way I used:

安装问题中提到的所有更新后,我遇到了完全相同的问题。我相信有不同的方法可以解决这个问题。这是我使用的方法:

Previously, when an activity was created, the following project was automatically generated by the wizard:

以前,在创建活动时,向导会自动生成以下项目:

androi-support-v7-appcompatand this project was added to the build path.

androi-support-v7-appcompat并且此项目已添加到构建路径中。

After all the updates, the following equivalent is generated when an activity is created:

在所有更新之后,创建活动时会生成以下等效项:

appcompat_v7with the jars of the same names. I deleted androi-support-v7-appcompatand made sure the projects use appcompat_v7to replace androi-support-v7-appcompatin their build paths. This made hundreds of errors generated by the duplicates go away.

appcompat_v7与同名的罐子。我删除了androi-support-v7-appcompat并确保项目使用appcompat_v7来替换 它们构建路径中的androi-support-v7-appcompat。这使得重复产生的数百个错误消失了。

回答by Riddhi Dudani

I am glad that i finally found the answer. I was encountering the same problem again and again and i was like fed up.

我很高兴我终于找到了答案。我一次又一次地遇到同样的问题,我已经受够了。

Here is the answer to your question.

这是您问题的答案。

whenever you get such an error just don't touch anything other than libsfolder. Just go directly into the libs folder and right away delete the android-support-v4.jar. and clean build your project. You will be relieved to get rid of errors.

每当您遇到此类错误时,请不要触摸libs文件夹以外的任何内容。只需直接进入 libs 文件夹并立即删除android-support-v4.jar。并清理构建您的项目。消除错误后,您将感到宽慰。

Hope its useful to you. Keep coding..

希望对你有用。继续编码..