Android studio appcompat error

Different Ways to fix Cannot resolve symbol ‘AppCompatActivity’ in Android Studio

When you create a project and extends activity AppCompatActivity, sometimes you must have observed Android Studio throws an error that is:

Cannot resolve symbol ‘AppCompatActivity’

and this error doesn’t go away easily. In this article, we are going to cover topics: why there is a need to solve this error and five different ways to get rid of this error.

Why There is a Need To Solve “Cannot resolve symbol ‘AppCompatActivity’”?

When you rename the application package name this error pops up. The import statement turns gray and says there’s no package for support.v7.app. Even after upgrading to appcompat-v7:22.1.0, in which AppCompatActivty (To get the most out of the Android Support Library that is, to get the latest features supported across the highest number of devices, we need AppCompatActivity) is added, the problem doesn’t go away. So we need to try the following methods to fix this problem in Android Studio.

How To Solve “Cannot resolve symbol ‘AppCompatActivity’”?

Method 1

  • Go to your build.gradle(Module:app) file and in the dependencies section the appcompat one, you should see something like compile ‘com.android.support:appcompat-v7:XX.X.X’, change it to compile ‘com.android.support:appcompat-v7:XX.X.+’ or else hit ALT + ENTER on both appcompat & design dependencies then select the shown version.
  • Then click on Sync.

Method 2

Navigate to File > Invalidate Caches/Restart and then disable offline mode and sync.

Method 3

Step 1: Delete the .idea folder. For .idea folder navigate to YourProject > app > .idea

Step 2: Close and reopen the project

Step 3: File > Sync Project With Gradle Files

Источник

Ошибка AppcompatActivity с Android studio

Я получаю эту ошибку при создании приложения android с Android studio:

большое спасибо за вашу помощь

старые действия, которые наследуются от AppcompatActivity, работают нормально. но если я создам новый, он получит ошибку . вот мой Gradle в.build:

Читайте также:  Для чего андроид студио нужен

9 ответов

у вас есть эта проблема, потому что вы пытаетесь использовать onCreate (Bundle savedInstanceState, PersistableBundle persistentState), но этот метод доступен только с уровня API 21.

Я могу воспроизвести проблему с этим образцом кода на Android 4.4:

и проблема решена удаление каждого вхождения PersistableBundle :

проверьте, где вы используете PersistableBundle в своем TourActivity и удалите его или обновите свой ответ с помощью код вашей деятельности.

обновите библиотеку поддержки до 23 и свой compileSdkVersion to 23 в build.градля.

затем синхронизируйте проект с файлами gradle.

кроме того, Google Play Services теперь 7.8.0

проблема в том, что ваш TourActivity использует класс, доступный только с уровня API 21 PersistableBundle. Вопрос в том, почему это происходит.

помните, что новая деятельность должна наследовать от AppCompatActivity Как хорошо.

быстрый вопрос, вы переопределение public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) в проблемной деятельности? Если вы это делаете, вы, вероятно, сохраняете ссылку на PersistableBundle который недоступен в устройстве / эмуляторе. Попробуйте удалить его, если вы не делаете ничего нет или прокомментировать его попробовать.

во-первых, обновите библиотеки до последних версий. Затем очистите и перестройте свой проект.

кроме того, если это полный список библиотек, которые вы включаете:

тогда вам на самом деле не нужно включать этот

вот дрянное решение, но оно действительно сработало для меня ! Я вручную создал необходимый путь к отсутствующей библиотеке:

и добавил два недостающих .файлы jar из здесь и здесь. Android studio наконец-то нашла зависимости, необходимые для выполнения Java.

просто , перейти на ->аннулировать кэш и перезапустить. Спасибо

1.Просто измените свои зависимости, чтобы представить их в сборке.градля—

2.Затем он покажет синхронизировать gradle, а затем синхронизировать сборку.gradle для обновления изменений.

у меня была такая ошибка, и если вы хотите решить, вы должны изменить вот так

Источник

Возникают ошибки в com.android.support:appcompat-v7:28.0.0 что делать?

до момента все работало нормально. приложение компилировалось . даже выложил на гугл плей.
что я сделал не так? в builde.gradle подчеркивает красным цветом implementation ‘com.android.support:appcompat-v7:28.0.0

при компиляции вылетает ошибка такая:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class androidx.core.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class androidx.core.internal.package-info found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.NonParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelUtils found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$ParcelException found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream$FieldBuffer found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream$InputBuffer found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelize found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)

Go to the documentation to learn how to Fix dependency resolution errors.

Читайте также:  Smart cover для андроида

Источник

Fix “Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]” in Android Studio

Implementation is a dependency configuration used for library declaration and was introduced in the Android Gradle Plugin 3.0 by Google. Implementation dependencies are declared in this configuration which is internal and not meant for consumer exposure. The main reason for “Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]”” error is that the Gradle cannot recognize the implementation configuration. In this article, we will be discussing 5 different methods to solve this error.

  • Method 1: Update to the latest Gradle version
  • Method 2: Change “implementation” to “compile”
  • Method 3: Move dependencies to module build.gradle
  • Method 4: Change apply plugin: “java” to “java-library”
  • Method 5: Change “implementationSdkVersion” to “compileSdkVersion”

Method 1: Update to the latest Gradle version

In case you are using the “implementation” configuration in an older version of Gradle, the Gradle will not recognize it and throw this error. Hence updating Gradle and Gradle build plugin to the latest version can help solve this issue.

Step 1: Navigate to app > Gradle Script > build.gradle (Project: app). Now inside the “dependencies” block, update the classpath to the latest version of the Gradle build plugin.

Step 2: Now navigate to app > Gradle Script > gradle-wrapper.properties and update the “distributionUrl” to the latest version of Gradle. After adding this code sync your project to solve this issue.

Method 2: Change “implementation” to “compile”

If you are using the “implementation” configuration in a Gradle Plugin version less than 3.0, the Gradle will not recognize it and will throw this error. Hence changing “implementation” to “compile” would work. Navigate to app > Gradle Script > build.gradle (Module:app). Inside the dependencies block change “implementation” to “compile“, “testImplementation” to “testCompile” and “androidTestImplementation” to “androidTestCompile“.

Читайте также:  Android media server отключить

Method 3: Move dependencies to module build.gradle

In Android Studio, there is two build.gradle files. One is for the Project level and another one for the Module level. If application dependencies are added in the Project level build.gradle file, it throws the error “Could not find implementation() method”. Adding these dependencies into the module build.gradle can help solve this issue.

Method 4: Change apply plugin: “java” to “java-library”

The Java Library plugin expands the capabilities of the Java plugin by providing specific knowledge about Java libraries. Change the code inside the Module level build.gradle from

After adding this code sync your project to solve this issue.

Method 5: Change “implementationSdkVersion” to “compileSdkVersion”

The version of the compiler used while building the app is determined by the “compileSdkVersion” while there is no such method as “implementationSdkVersion” in Gradle. Hence changing “implementationSdkVersion” to “compileSdkVersion” can solve this issue. Navigate to app > Gradle Script > build.gradle (Module:app). Change the code from

After adding this code sync your project to solve this issue.

Источник

Оцените статью