I am getting the error: "Ambiguous method call" on initializing Toolbar using Android Studio 3.0 RC1. I have extended my Activity with AppCompatActivity and compiling my application using 'compileSdkVersion 26'. Attaching a screenshot of the error.
我在使用Android Studio 3.0 RC1初始化工具栏时收到错误:“模糊方法调用”。我已经使用AppCompatActivity扩展了我的Activity并使用'compileSdkVersion 26'编译我的应用程序。附上错误的屏幕截图。
12 个解决方案
#1
11
If you recently updated your project to API, Try doing
如果您最近将项目更新为API,请尝试执行
File -> Invalidate Caches / Restart
文件 - >使高速缓存/重新启动无效
then
File -> Sync Project with Gradle Files
文件 - >使用Gradle文件同步项目
this resolve for me.
这个决心对我而言。
#2
5
Upgrade to appcompat 27 solved this for me
升级到appcompat 27为我解决了这个问题
#3
4
For me changing build tool version to 27.0.2 worked, given that all your other dependencies are API 27 as well.
对于我来说,将构建工具版本更改为27.0.2,因为所有其他依赖项都是API 27。
buildToolsVersion '27.0.2'
#4
3
You have
import android.support.v7.app.AppCompatActivity
import android.app.Activity
both in your code. Remove import android.app.Activity
as I can see, it's not required for you.
在你的代码中。我可以看到删除导入android.app.Activity,这不是你需要的。
#5
3
"File - Invalidate Caches / Restart" Solved my problem.
“文件 - 无效缓存/重新启动”解决了我的问题。
#6
3
I have recently upgraded to build tools version 27.0.2 and faced the same problem. But noticed that I had the compileSdk version set to 25. Changing compileSdk to 27 resolved the issue.
我最近升级到构建工具版本27.0.2并遇到了同样的问题。但是注意到我将compileSdk版本设置为25.将compileSdk更改为27可以解决问题。
#7
2
For me none of the given solutions worked, however I had this issue because I had both 25 and 27 android sdk installed on my computer. As soon as I removed the sdk 25, the problem disappeared.
对我来说,没有一个给定的解决方案有效,但我遇到了这个问题,因为我的计算机上安装了25和27个android sdk。一旦我删除了sdk 25,问题就消失了。
#8
1
Maybe you have difference between compileSdkVersion and targetSdkVersion
也许你在compileSdkVersion和targetSdkVersion之间有区别
#9
1
I ran into the same issue with Android Studio 3.0.0 build 171.4408382. Building via Gradle on the command line worked just fine, but the IDE presented me with the above mentioned error. I have tried to use API level 26 with appcompat v26.1.0 and API level 27 with appcompat v27.0.1, but neither combination worked.
我遇到了与Android Studio 3.0.0 build 171.4408382相同的问题。在命令行上通过Gradle构建工作正常,但IDE向我提出了上述错误。我尝试将API级别26与appcompat v26.1.0和API级别27与appcompat v27.0.1一起使用,但两种组合均无效。
My "solution" was to downgrade compileSdkVersion and targetSdkVersion to API level 25 and the appcompat library to version 25.4.0.
我的“解决方案”是将compileSdkVersion和targetSdkVersion降级到API级别25,将appcompat库降级到25.4.0版本。
For all of the mentioned version combinations I used Gradle plugin v3.0.0 and the Android build tool v27.0.1.
对于所有提到的版本组合,我使用了Gradle plugin v3.0.0和Android构建工具v27.0.1。
#10
1
This can suddenly appear when running a code analyzer like FindBugs-IDEA. A quick way to clear the warning is to temporarily change the buildToolsVersion
in your app/build.gradle
then change it back again.
运行像FindBugs-IDEA这样的代码分析器时,这可能会突然出现。清除警告的一种快速方法是临时更改app / build.gradle中的buildToolsVersion,然后再将其更改回来。
For example, follow these steps:
例如,请按照下列步骤操作:
- Open your app/build.gradle file.
- Change
buildToolsVersion
to'26.0.1'
then sync project (press the 'Sync Now' button when it appears at the top) - Change the
buildToolsVersion
back to whatever you had before. - Press the 'Sync Now' button
打开app / build.gradle文件。
将buildToolsVersion更改为'26 .0.1'然后同步项目(当它出现在顶部时按下'立即同步'按钮)
将buildToolsVersion更改回以前的任何内容。
按“立即同步”按钮
This should clear the error.
这应该清除错误。
#11
0
if answers does not resolve your problem , you can reset your android studio. I solved with reset my android studio. For reset: https://*.com/a/19397632/3129822
如果答案无法解决您的问题,您可以重置您的Android工作室。我解决了重置我的android工作室。重置:https://*.com/a/19397632/3129822
#12
0
First make sure that you have no transitive dependencies that are using older support libraries. Run the following command and make sure that no older support libraries are in use.
首先确保您没有使用旧支持库的传递依赖项。运行以下命令,并确保没有使用旧的支持库。
gradlew :app:dependencies
Make sure that your gradle file is updated with latest dependencies. eg: compileSdkVersion 27, targetSdkVersion 27, buildToolsVersion 27.0.3. etc. It would also benefit to make sure that non of your app flavors have been using a custom targetSdkVersion.
确保使用最新的依赖项更新gradle文件。例如:compileSdkVersion 27,targetSdkVersion 27,buildToolsVersion 27.0.3。确保您的应用程序风味非使用自定义targetSdkVersion也是有益的。
Ctrl + click on the findViewById method. It will show you the 2(perhaps more?) conflicting methods. In my case the conflict was between the findViewById method from API 23 and API 27. Therefore I had to remove the SDK and sources for Android version 23. Once I removed it and did Invalidate Caches/Restart it solved my problem.
按住Ctrl键并单击findViewById方法。它会告诉你2个(可能更多?)冲突的方法。在我的情况下,冲突发生在API 23和API 27的findViewById方法之间。因此,我不得不删除Android版本23的SDK和源代码。一旦我删除它并执行Invalidate Caches / Restart,它就解决了我的问题。
#1
11
If you recently updated your project to API, Try doing
如果您最近将项目更新为API,请尝试执行
File -> Invalidate Caches / Restart
文件 - >使高速缓存/重新启动无效
then
File -> Sync Project with Gradle Files
文件 - >使用Gradle文件同步项目
this resolve for me.
这个决心对我而言。
#2
5
Upgrade to appcompat 27 solved this for me
升级到appcompat 27为我解决了这个问题
#3
4
For me changing build tool version to 27.0.2 worked, given that all your other dependencies are API 27 as well.
对于我来说,将构建工具版本更改为27.0.2,因为所有其他依赖项都是API 27。
buildToolsVersion '27.0.2'
#4
3
You have
import android.support.v7.app.AppCompatActivity
import android.app.Activity
both in your code. Remove import android.app.Activity
as I can see, it's not required for you.
在你的代码中。我可以看到删除导入android.app.Activity,这不是你需要的。
#5
3
"File - Invalidate Caches / Restart" Solved my problem.
“文件 - 无效缓存/重新启动”解决了我的问题。
#6
3
I have recently upgraded to build tools version 27.0.2 and faced the same problem. But noticed that I had the compileSdk version set to 25. Changing compileSdk to 27 resolved the issue.
我最近升级到构建工具版本27.0.2并遇到了同样的问题。但是注意到我将compileSdk版本设置为25.将compileSdk更改为27可以解决问题。
#7
2
For me none of the given solutions worked, however I had this issue because I had both 25 and 27 android sdk installed on my computer. As soon as I removed the sdk 25, the problem disappeared.
对我来说,没有一个给定的解决方案有效,但我遇到了这个问题,因为我的计算机上安装了25和27个android sdk。一旦我删除了sdk 25,问题就消失了。
#8
1
Maybe you have difference between compileSdkVersion and targetSdkVersion
也许你在compileSdkVersion和targetSdkVersion之间有区别
#9
1
I ran into the same issue with Android Studio 3.0.0 build 171.4408382. Building via Gradle on the command line worked just fine, but the IDE presented me with the above mentioned error. I have tried to use API level 26 with appcompat v26.1.0 and API level 27 with appcompat v27.0.1, but neither combination worked.
我遇到了与Android Studio 3.0.0 build 171.4408382相同的问题。在命令行上通过Gradle构建工作正常,但IDE向我提出了上述错误。我尝试将API级别26与appcompat v26.1.0和API级别27与appcompat v27.0.1一起使用,但两种组合均无效。
My "solution" was to downgrade compileSdkVersion and targetSdkVersion to API level 25 and the appcompat library to version 25.4.0.
我的“解决方案”是将compileSdkVersion和targetSdkVersion降级到API级别25,将appcompat库降级到25.4.0版本。
For all of the mentioned version combinations I used Gradle plugin v3.0.0 and the Android build tool v27.0.1.
对于所有提到的版本组合,我使用了Gradle plugin v3.0.0和Android构建工具v27.0.1。
#10
1
This can suddenly appear when running a code analyzer like FindBugs-IDEA. A quick way to clear the warning is to temporarily change the buildToolsVersion
in your app/build.gradle
then change it back again.
运行像FindBugs-IDEA这样的代码分析器时,这可能会突然出现。清除警告的一种快速方法是临时更改app / build.gradle中的buildToolsVersion,然后再将其更改回来。
For example, follow these steps:
例如,请按照下列步骤操作:
- Open your app/build.gradle file.
- Change
buildToolsVersion
to'26.0.1'
then sync project (press the 'Sync Now' button when it appears at the top) - Change the
buildToolsVersion
back to whatever you had before. - Press the 'Sync Now' button
打开app / build.gradle文件。
将buildToolsVersion更改为'26 .0.1'然后同步项目(当它出现在顶部时按下'立即同步'按钮)
将buildToolsVersion更改回以前的任何内容。
按“立即同步”按钮
This should clear the error.
这应该清除错误。
#11
0
if answers does not resolve your problem , you can reset your android studio. I solved with reset my android studio. For reset: https://*.com/a/19397632/3129822
如果答案无法解决您的问题,您可以重置您的Android工作室。我解决了重置我的android工作室。重置:https://*.com/a/19397632/3129822
#12
0
First make sure that you have no transitive dependencies that are using older support libraries. Run the following command and make sure that no older support libraries are in use.
首先确保您没有使用旧支持库的传递依赖项。运行以下命令,并确保没有使用旧的支持库。
gradlew :app:dependencies
Make sure that your gradle file is updated with latest dependencies. eg: compileSdkVersion 27, targetSdkVersion 27, buildToolsVersion 27.0.3. etc. It would also benefit to make sure that non of your app flavors have been using a custom targetSdkVersion.
确保使用最新的依赖项更新gradle文件。例如:compileSdkVersion 27,targetSdkVersion 27,buildToolsVersion 27.0.3。确保您的应用程序风味非使用自定义targetSdkVersion也是有益的。
Ctrl + click on the findViewById method. It will show you the 2(perhaps more?) conflicting methods. In my case the conflict was between the findViewById method from API 23 and API 27. Therefore I had to remove the SDK and sources for Android version 23. Once I removed it and did Invalidate Caches/Restart it solved my problem.
按住Ctrl键并单击findViewById方法。它会告诉你2个(可能更多?)冲突的方法。在我的情况下,冲突发生在API 23和API 27的findViewById方法之间。因此,我不得不删除Android版本23的SDK和源代码。一旦我删除它并执行Invalidate Caches / Restart,它就解决了我的问题。