Error : Ambiguous method call. Both findViewById (int) in AppCompactActivity and Activity

后端 未结 17 2488
我寻月下人不归
我寻月下人不归 2021-02-05 00:29

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 appli

17条回答
  •  青春惊慌失措
    2021-02-05 00:57

    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.

    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.

提交回复
热议问题