I am trying to make runtime permissions backward compatible with older devices but using the support library i cant find checkSelfPermission() static call in ContextCompat class, but its documented here
Here is my project gradle settings:
defaultConfig {
applicationId "org.myprogram.cool"
minSdkVersion 16
targetSdkVersion 23
versionCode 39
versionName "3.0"
}
and here is the dependencies:
compile 'com.google.android.gms:play-services:+'
compile 'com.squareup:otto:1.3.5'
compile 'com.android.support:appcompat-v7:22.1.1'
any idea what i am missing ?
checkSelfPermission() didn't get introduced into the native Context until API 23. So you will need to use at least version 23.0.0 of the support library.
You should change this
compile 'com.android.support:appcompat-v7:22.1.1'
to this
compile 'com.android.support:appcompat-v7:23.0.1'
If you have migrated from eclipse adding the below line wont work
compile 'com.android.support:appcompat-v7:23.0.1'
While migrating, it adds appcompatv4 as an external dependent library.
Make sure you have deleted the appcompatv4 library from the libs folder and then it should start working
Make sure class exampleActivity class is extending from AppCompatActivity.
Make sure that your minSdkVersion is 23 in the build.gradle file.
Sync your gradle after making this change.
That should work.
Related
After updating Android Studio from 2.3 to 3.0 I changed buildToolsVersion from 26.0.0 to 26.0.2 and after that I am getting this error:
Cannot resolve symbol '?attr/actionBarSize
Xml code:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#android:color/white"/>
Dependencies:
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
Nothing helped, but changing:
?attr/actionBarSize to ?android:attr/actionBarSize did the job.
That's actually a bug in few versions. Even if you won't fix it, Android will automatically fix it at runtime.
Update all your library versions to 26.1.0 (to the most recent version) and also add:
compile 'com.android.support:support-v4:26.1.0'
if you are using Android Studio 3.0.0 and above then use
implementation 'com.android.support:support-v4:26.1.0'
Sync your project and the error will automatically resolve because ?attr/actionBarSize is part of v4 library.
In the project directory hierarchy switch "Android" to "Project".
Then delete a folder ".idea/libraries", only "libraries".
Select an option from the menu "File -> Invalidate Caches / Restart... -> Invalidate and Restart".
Good day, I know this is a bit late.
but I have encountered this one too, when I updated to Android Studio 3.0
what i did is I changed
compile 'com.android.support:support-v4:26.1.0'
to
implementation 'com.android.support:support-v4:26.1.0'
Hope it can help somebody.
This is what I did to fix exactly the same problem.
1. Go to SDK manager.
2. Check Android API 27 and Android 8.0 (Oreo)
3. Click "Apply" to download and install those SDKs
4. In build.gradle, change the 'buildToolsVersion "26.0.1"' to 'buildToolsVersion "26.0.2"' and do a gradle sync.
Hope this can help fix your issue.
Your buildToolsVersion version differs from version in dependencies
(e.g. buildToolsVersion is 27.0.0
but implementation 'com.android.support:support-v4:27.0.1'). Make them the same.
my problem solved by changing compileSdkVersion and targetSdkVersion from 26 to the last version 27, also u need to upgrade ur dependencies to 27.
android {
compileSdkVersion 27
defaultConfig {
applicationId "com......"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
}
hope this solve ur problem too :)
Try to add this in your build.gradle(app) dependencies:
resolutionStrategy {
force libraries.support.appCompat
force libraries.support.design
force 'com.android.support:support-utils:26.0.1'
force 'com.android.support:support-compat:26.0.1'
}
This worked.
I have updated the compile and support lib versions from 26.x.x to 27.x.x.
I tried all the answers here and so many others from lots of places but only the below techniques worked for me.
The simple way is you just need to close the project then import the same project as a Gradle project
Or you can go to Project structure -> project -> change Gradel plugin = 4.4 and Android plugin version = 3.1.4.
Both of these above methods work.
Note: These versions(4.4, 3.1.4) are latest when I write this answer please use the latest version instead of these.
Same issue here, if you're using AndroidX add this :
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Change R.attr.actionBarSize to androidx.appcompat.R.attr.actionBarSize.
Maybe you hava upgraded the version of gradle.
when my gradle version is 4.4 and plugin version is 3.1.1.It is ok.
this work:
delete all file in $HOME/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar
Changed all Support Library versions to the newest 27.1.1 and the error was gone.
please replace android support libraries.
from
27.1.1
to
28.0.0-alpha3
and replace 27 to 28 for following cases:
compileSdkVersion 28
buildToolsVersion "28.0.0"
targetSdkVersion 28
this will fix the issue.
Android beginner here...
I'm getting all sort of rendering errors, and eventually concluded it's got something to do with my gradle dependencies.
Now I found a nice tutorial which I've been following, http://www.android4devs.com/2015/06/navigation-view-material-design-support.html but I'm running to a problem extending it further, and there is something I don't think I understand.
Should I not be using the latest stable version of any library I can? Surely these libraries are backwards compatible?
If I am supposed to use the older version of library, to match the compile sdk (which I understand to mean I'm compiling for backwards compatibility, and supporting, say, lollipop API 21-22) then:
I would need a place to see a complete list of all versions of all libraries (which I cannot find), and
I would not be able to use new features like RecyclerView which only came in at Marshmallow API 23.
Am I missing something?
build.gradle (module app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.myFirstApp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
...
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.intuit.sdp:sdp-android:1.0.3'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
Error message
The support library should not use a different version (26) than the compile sdk version (22).
You are using
compileSdkVersion 22
and
compile 'com.android.support:appcompat-v7:26.1.0'
error you are getting is because you are using compat version 26 while compileSdkversion is 22
You should update to compileSdkVersion to 26 and android studio will download required files so that your error will be removed. If you cannot update your compilesdk version to 26. Then change support library version to 22.2.1
compile 'com.android.support:appcompat-v7:22.2.1'
Got list of support libraries from link
https://developer.android.com/topic/libraries/support-library/rev-archive.html
and
https://developer.android.com/topic/libraries/support-library/revisions.html
I am facing a strange issue, i installed latest appcompat-v7:23.0.0
Where as i got to know i must not need it but i need to go with appcompat-v7:22.2.1 or appcompat-v7:22.0.0
I updated my gradle as per my needs but it always pickup appcompat-v7:23.0.0 which is not required, any one guide me how can i resolve this issue?
Since you are using
compile 'com.google.android.gms:play-services:+'
you are using the latest version compile 'com.google.android.gms:play-services:8.4.0' which has a dependency with support libraries v23.
You have to compile with API 23.
Change this line:
compileSdkVersion 23
If you don't want to use the api23 you can use a specific version like as
compile 'com.google.android.gms:play-services:7.8.0'
In general is not a good practice the use of + in your dependencies because you can't replicate the build in the future with the same libraries and you don't know which version you are using.
Also you can use api23 with Httpclient.
Just use:
android {
useLibrary 'org.apache.http.legacy'
}
More info here.
The useLibrary requires the gradle plugin 1.3.0 (classpath 'com.android.tools.build:gradle:1.3.0') or higher.
AppCompat (aka ActionBarCompat) started out as a backport of the
Android 4.0 ActionBar API for devices running on Gingerbread,
providing a common API layer on top of the backported implementation
and the framework implementation. AppCompat v21 delivers an API and
feature-set that is up-to-date with Android 5.0
You can use
compile 'com.android.support:appcompat-v7:22.0.1'
Finally
android {
compileSdkVersion 22
buildToolsVersion '22.0.1' // You can set buildToolsVersion '23.0.1'
Advice
You should use
compile 'com.google.android.gms:play-services:7.8.0' // or 8.4.0
Good Approach : Use latest Version .
you need to download the latest support repository from internal SDK
manager of Android Studio or from the stand alone SDK manager. Then
you can add compile 'com.android.support:appcompat-v7:23.0.1'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId ""
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:7.8.0' // or 8.4.0
}
Edit
You can use this classpath
classpath 'com.android.tools.build:gradle:1.3.0'
Then Clean-Rebuild-Restart-Sync your project . Hope this helps .
I'm trying to create a new list using RecyclerView to convert my existing ListView but problem is I can't find why my app cannot import the RecyclerView. I've just updated my SDK and other tools so I can work with Marshmallow in the future so everything is updated.
What I have in my app build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23"
defaultConfig {
applicationId "com.test.recyclerview"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:percent:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
}
and after adding this line on my layout xml I got the error saying The following classes could not be found: -android.support.v7.widget.RecyclerView
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
Downgrading my buildtools and targetSDK version is quite not a good option for me since I only have version 22 and 23 but in case I tried to downgrade my app compat version into 21 it result into this error:
This support library should not use a lower version (21) than the targetSdkVersion (23)
Does it mean that the RecyclerView is removed from app compat 23? or I missed something here?
It appears that something was messed out with my configuration which cause is still unknown. It may be on the IML file or other part but it appears that the libraries are not being imported from the source which is why even after I sync and clean the gradle project the libraries from external source remains the same and still builds successfully.
This may be a stupid question but it's the only thing I can imagine is happening
You said that you had downloaded Marshmallow API but have you downloaded the Android Support Library?
The RecyclerView is part of the support library, not the "normal" SDK
Today, Google released SDK 6 API 23+.
I tried to create a project with the API 23, but I'm having the following problem:
Failed to resolve: com.android.support:appcompat-v7:23.0
Here's my gradle file:
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "my.package"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
compile 'com.android.support:appcompat-v7:23.0'
compile 'com.google.android.gms:play-services:7.8.0'
}
In the SDK manager, the version 23 isn't listed to update:
How can I solve this?
Original answer:
I too tried to change the support library to "23". When I changed the targetSdkVersion to 23, Android Studio reported the following error:
This support library should not use a lower version (22) than the targetSdkVersion (23)
I simply changed:
compile 'com.android.support:appcompat-v7:23.0.0'
to
compile 'com.android.support:appcompat-v7:+'
Although this fixed my issue, you should not use dynamic versions. After a few hours the new support repository was available and it is currently 23.0.1.
Pro tip:
You can use double quotes and create a ${supportLibVersion} variable for simplicity. Example:
ext {
supportLibVersion = '23.1.1'
}
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:palette-v7:${supportLibVersion}"
compile "com.android.support:customtabs:${supportLibVersion}"
compile "com.android.support:gridlayout-v7:${supportLibVersion}"
source: https://twitter.com/manidesto/status/669195097947377664
As seen in the revision column of the Android SDK Manager, the latest published version of the Support Library is 22.2.1. You'll have to wait until 23.0.0 is published.
Edit: API 23 is already published. So u can use 23.0.0
Ran into a similar issue using React Native
> Could not find com.android.support:appcompat-v7:23.0.1.
the Support Libraries are Local Maven repository for Support Libraries
First you need to download the latest support repository (17 by the time I write this) from internal SDK manager of Android Studio or from the stand alone SDK manager. Then you can add compile 'com.android.support:appcompat-v7:23.0.0' or any other support library you want to your build.gradle file. (Don't forget the last .0)
Latest published version of the Support Library is 24.1.1, So you can use it like this,
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
Same as for other support components.
You can see the revisions here,
https://developer.android.com/topic/libraries/support-library/revisions.html