Error after adding AppCompat v7 in Android Studio - android

After adding the appCompat v7 library I get the error that R cannot be resolved, which is apparently due to the fact that R now exists twice. I found an answer to that problem here : Build errors after adding fullscreen activity in Android Studio
However, I dont have or cant find the file attrs.xml in \src\main\res\values\attrs.xml. Is there any other solution to that problem or can someone give me a detailed description of how to do that in Android Studio?
Thank you very much!!!

Put this in your /app/build.gradle file :
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:18.0.0'
}
and make sure the version code (here 18.0.0) is not higher than the buildToolsVersion in the same file :
android {
compileSdkVersion 16
buildToolsVersion "18.0.0"
}
then rebuild your project. Hope that helps!
Oh and make sure you have the right buildTools installed via SDK Manager! Actual version is 21.0.2 I think.

I'm may be noob, but after several search i was able to add appcompat.v7 in android studio.
Initially i was comfortable with Eclipse after Dex Error 65535, my whole hard work was doomed i thought.
As Honey suggested you have to add both support.v4 or v13 and appcompat.v7 in build.gradle.
That's it. This simple solution not even covered in google docs ;). A simple reminder appcompat depends on v4 or v13.

Related

No access to androidx.media (while building mediastyle notification)

I am trying to add MediaStyle notification buttons to my application. I am a bit stuck. Most guides assume access to the support library. But I think that is not a good idea for my new project and I should use androidx. I hope to have as low as possible future maintenance.
My minSdkVersion is 21 and compileSdkVersion and targetSdkVersion are 29.
Using these class mappings, I found that
The support libraries in android.support.mediacompat.R are now located in androidx.media.R
But, my androidx has no media namespace. (I think this is my main problem).
In my build.gradle I have listed
implementation 'androidx.core:core:1.1.0'
implementation 'androidx.media:media:1.1.0'
And in gradle.properties I have listed (added by android studio on new project init)
android.useAndroidX=true
android.enableJetifier=true
I hope you guys have an idea where to look. Thanks :)
Oh wow. Gradle didn't sync. A gradle sync solved it. pff

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

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.
If you recently updated your project to API, Try doing
File -> Invalidate Caches / Restart
then
File -> Sync Project with Gradle Files
this resolve for me.
Upgrade to appcompat 27 solved this for me
For me, it was the compileSdkVersion which was different than the support libraries used
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.
For me changing build tool version to 27.0.2 worked, given that all your other dependencies are API 27 as well.
buildToolsVersion '27.0.2'
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.
"File - Invalidate Caches / Restart" Solved my problem.
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.
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.
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
This should clear the error.
Maybe you have difference between compileSdkVersion and targetSdkVersion
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.
My "solution" was to downgrade compileSdkVersion and targetSdkVersion to API level 25 and the appcompat library to version 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.
In my case, I removed the constraint layout dependency in the build.gradle (app) file and it solved the issue.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.1.0'
//implementation 'com.android.support.constraint:constraint-layout:2.0.4'
}
if answers does not resolve your problem , you can reset your android studio.
I solved with reset my android studio.
For reset: https://stackoverflow.com/a/19397632/3129822
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.
My compileSDK version was lower than the targetSDK version so all I had to do was match them and sync project and the error was resolved.
Removing "Android Fast Networking" library solved my problem
I've had the same issue
Mine was related to the compileSdkVersion number from build.gradle app.
Changed to the latest and it worked for me.
Upgrading your targetSdkVersion or buildToolsVersion might resolve the problem.
No need to Invalidate Caches / Restart if this is a new project.
I was working with a new project and in gradle files did not have version numbers set in them, there was "N" across minsdkversion and targetsdkversion, changing to desired sdk version solved the problem
Upgrading both appcompat to 27 and compleSdkVersion to 30 works for me.Just upgrade those in gradle build.
Just upgrade your minSdkVersion 26 Its works for me.
When we create a Android project with minimum SDK lower than 16 and after that we want to add new activity using 'New/Activity/Gallery' we see the indication 'Selected activity templates has minimum SDK level of 16'. So we need to modify 'minSdkVersion' in build.gradle file which leads us to 'Sync Now' process.
If we must build and maintain an app with min SDK lower then 16, we have to change 'constraint layout' to another layout. However when we do this the constraint layout dependency still remains in the dependencies section in the 'build.gradle' file. This caused me the error.
In summary, this is applicable when we need to build a android project with minimum SDK version lower than 16.
When we add a new activity, we change the minSdkVersion in the build.gradle above '16' then click of 'Sync Now'. After that we can choose one of activity template and create a new activity.
Now we change 'constraint layout' in the xml file corresponds to the new activity we created to for example 'linear layout' or 'relative layout'
At this point we make sure delete the dependency which refers to constraint layout in the 'build.gradle' and then click the 'Sync Now' again.
I think the best practice to avoid this error message is to make Android project with minimum SDK 16 and above.
These steps worked for me on Android Studio for Mac (Arctic Fox v11):
In 'build.gradle' file (for module), change appcompat implementation version to something invalid (e.g. Change 'com.android.support:appcompat-v7:25.1.0' to 'com.android.support:appcompat-v7:25')
Click 'Gradle sync now' and let it finish. This should generate lots of errors
Correct the verison back to original (e.g. 'com.android.support:appcompat-v7:25.1.0'). Click 'Gradle sync now' and let it finish
Original issue with findViewId should disappear

appcompat version and declaration issue

i try to migrate minSDK from 9 to 14 (that's newest play_services minimum). Target SDK is 17. When i change it manually in gradle and manifest after sync, a huge list of problems showing up. Most of them has something in common with appcompact.
E:\Android\Android\android studio projects\Sklepik\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.0.0\res\values-v23\values-v23.xml
I think that these problems are because wrong version is in use (project works good few months ago), but i can't find place of declaration appcompact.
Right now i've got 2 dependiences in gradle:
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services:10.2.0'
}
How to solve it?
---> Keyur, after change support version i have problem which looks like:
of course my internet connection is ok...
Add support v7 library
compile 'com.android.support:support-v7:19.1.0'

The following classes could not be found: - android.support.design.widget.TextInputLayout

This is Tutorial which i am following.
Please help me out from this error. Rebuild is not solving the problem.
Does your build.gradle file contain the line below?
compile 'com.android.support:design:22.2.0'
You must include support libraries (like the ones below), yet this is sometimes not sufficient.
compile ("com.android.support:support-v4:23.3.0")
compile ("com.android.support:appcompat-v7:23.3.0")
compile ("com.android.support:support-annotations:23.3.0")
compile ("com.android.support:recyclerview-v7:23.3.0")
compile ("com.android.support:design:23.3.0")
Examine your layout in design view, and click on Show Exception
This answer will help if you have the following problem:
You need to use a Theme.AppCompat theme (or descendant) with the design library.
In your Manifest file, include in your application declaration
android:theme="#style/Theme.AppCompat"
Rebuild and your problem should be solved.
First things first :
If you are using the lastest sdk28 TextInputLayout is having some bug. At least mine did (date: 22 Sept 2018 ) NOT work.
To make it work the best way is to use slightly lower SDK for you target and compile SDK version. (I used sdk 27 and everything worked out fine then.)
To use TextInputLayout and then its features such as "floatinghinttext" you need to update your build.gradle(module.app) found in gradleScripts.
in dependencies add-
implementation 'com.android.support:design:25.0.0'
(if you get some error it must be of some latest version available, so use that instead of 25.0.0)
Note: The "compile" keyword is getting replaced by "implementation" for newer/all versions.
I am fairly new to android development, suggestions are welcomed. Please excuse if any mistakes committed.

Android Studio problems since the last update to 0.8 version

I'm following the Google I/O conference and just a week before they announced that Android Studio 0.8 is available for downloading. Before that I used 0.6 and I was developing an application. Now I'm having both 0.6 and 0.8 on my Ubuntu. I added all the update from SDK for Android Watch and TV and all the Material Design stuffs. And today when I opened my project in the 0.8 version, after a few updates of some things, I'm receiving an error
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version L declared in library com.android.support:appcompat-v7:21.0.0-rc1
If someone has any idea what is this all about - share please. I tried to pull my project from my repository in GitHub, but without any result. Thank you.
It looks like you have declared a dependency on version 21 of appcompat-v7 in your build.gradle.
At this time, the preview of the Android L support libraries only works with apps that declare the L preview as their min SDK.
Either revert to a previous version of the support library (I believe the latest is com.android.support:appcompat-v7:19.1.0) or update your project to support a minimum of 'L'.
just try this:
android {
android {
compileSdkVersion 20 //or whatever you want
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14 //or whatever you want
targetSdkVersion 20 //or whatever you want
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
}
}
and if you have another module in your project, check manifest files in those modules too.
I had a similar issue like that before. After I updated to 0.8.1, it showed an error below when compiling my previous projects.
"uses-sdk:minSdkVersion 8 cannot be smaller than version L declared in library com.android.support:appcompat-v7:21.0.0-rc1".
This is how I fixed it.
In your project, find build.gradle file in app folder and open it.
At dependencies section, change the value of compile 'com.android.support:appcompat-v7'. For example, in my case, it was compile 'com.android.support:appcompat-v7:+', and I changed it to compile 'com.android.support:appcompat-v7:20.+'. Of course, you could change it to compile 'com.android.support:appcompat-v7:19.+' if you like.
I hope it would help. Let me know if you are still stuck on it.
I had similar problems. Although I'm not sure exactly what caused the problem or which step fixed the issue, I did the following and ultimately got things working again:
I closed down Android Studio
I ran SDK Manager and and checked that everything was up to date. I have the following installed:
Android SDK tools Rev. 23
Android SDK Platform-tools Rev. 20
Android SDK Build-tools Rev. 20
Android L (API 20, L preview)
Android 4.4W (API 20)
Android 4.4.2 (API 19)
I restarted Android Studio and started a new (blank) project to test and ran it -> Success!
I found the process pretty finickity, so your mileage might vary. Let me know how you go.
I had the same error. I found the solution.
dependencies {
compile ('com.android.support:support-v13:20.0.0'){
force = true
}
compile ('com.android.support:support-v4:20.0.0'){
force = true
}
compile ('com.android.support:appcompat-v7:20.0.0'){
force = true
}
}
I think that instead of 20.0.0, you can specify a different version if you use less than 20 targetSdkVersion.
I had the same issue.
I made the following changes to the dependencies section in build.grade file located in the app folder.
'com.android.support:appcompat-v7:20.0.0' to 'com.android.support:appcompat-v7:20.+'

Categories

Resources