java.lang.NoSuchMethodError: No static method isDeviceProtectedStorage - android

I am trying to implement firebase into my project. But when the program run for the first time it shows this error :
java.lang.NoSuchMethodError: No static method isDeviceProtectedStorage(Landroid/content/Context;)Z in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/com.example.project-1/base.apk)
and below is my gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.project"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildToolsVersion "25.0.1"
sourceSets {
main {
aidl.srcDirs = ['src/aidl']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'src/main/jnilibs', include: ['.jar','.so'])
compile files('libs/gcm.jar')
compile files('libs/android-support-v7-recyclerview.jar')
compile files('libs/gson-2.7.jar')
compile files('libs/httpclientandroidlib-1.2.0.jar')
compile files('libs/logging-interceptor-3.0.1.jar')
compile files('libs/okhttp-3.0.1.jar')
compile files('libs/okhttp-urlconnection-3.0.1.jar')
compile files('libs/okio-1.10.0.jar')
compile files('libs/rollbar-android-0.1.3.jar')
compile files('libs/sherlocknavigationdrawer-1.0.jar')
compile files('libs/v7compat.jar')
compile files('libs/mpChart.jar')
compile files('libs/picasso-2.5.2.jar')
compile project(':actionbarsherlock')
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:support-v4:25.3.1'
compile 'de.hdodenhof:circleimageview:2.2.0'
compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.firebase:firebase-messaging:11.6.0'
}
apply plugin: 'com.google.gms.google-services'
I've read somewhere else it may be due to lower version of v4 support library. so I had it changed to higher api level, but the problem still persist. Any solution to solve this problem??

Reason of this exception is AppCompatActivity derived from the v7 library. so we should provide proper library based on your gradle and SDK.
You should update the dependency Libraries also.
Right click on the project in the project structure -> select Open module settings and select dependencies tab -> Library module-> then type which library you want add to the project. It shows the latest libraries based on your gradle updated version, then select latest one and remove the existing one.
For example In my project "appcompat-v7" version was 23.4.0 then I was changed to 27.0.2 which is latest one
Or try to use
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.android.support:appcompat-v7:27.0.2'

Related

Android dependency conflict error

I tried for many hours to find the solution but could not find. My problem is that when I build my Gradle I get two errors. I tried to look at this solution
Dependency conflict error in my Android app which has Android Tests but could still not solve the problem.
Error:Conflict with dependency 'junit:junit' in project ':app'. Resolved versions for app (4.10) and test app (4.12) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Conflict with dependency 'org.hamcrest:hamcrest-core' in project ':app'. Resolved versions for app (1.1) and test app (1.3) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Here's my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "voice.com.topsalai"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.3-
alpha', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'com.google.android.gms:play-services:10.2.4'
compile 'com.android.support:support-annotations:26.0.0-alpha1'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
How can I solve this?
dont use alpha..or beta.. just use the latest stable one..then please dont mix your android support version.. use same version for all android support
example
compile "com.android.support:appcompat-v7:25.3.1"
compile "com.android.support:cardview-v7:25.3.1"
compile "com.android.support:design:25.3.1"
compile "com.android.support:recyclerview-v7:25.3.1"
compile "com.android.support:support-annotations:25.3.1"
compile "com.android.support:support-v4:25.3.1"
compile "com.android.support:support-v13:25.3.1"
please remove this two dependency
testCompile 'com.android.support:support-annotations:26.0.0-alpha1'
androidTestCompile 'com.android.support:support-annotations:26.0.0-alpha1
I found the solution. By upgrading compileSdkVersion to
compileSdkVersion 25
And then Instead of this
compile 'com.android.support:appcompat-v7:23.1.1'
Only by updating appcompat-v7:23.1.1 did not solve it. I needed theese 3 lines of code.
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:animated-vector-drawable:25.3.1'
compile 'com.android.support:mediarouter-v7:25.3.1'

All android support libraries must use the same version specification

I dont know where I went wrong, but this keeps me saying
All com.android.support libraries must use the same exact version specification (mixing versions can lead to runtime crashes.) Found versions 24.0.0,23.2.0 Examples include com.android.support:animated-vector-drawable:24.0.0 and com.android.support:cardview-v7:23.2.0
my build.gradle is
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.project"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.mani:ThinDownloadManager:1.2.2'
compile 'net.rdrei.android.dirchooser:library:3.2#aar'
compile 'com.google.android.gms:play-services:10.2.0'
compile 'com.onesignal:OneSignal:3.+#aar'
}
apply plugin: 'com.google.gms.google-services'
It shows error in this line too
compile 'com.android.support:appcompat-v7:23.2.0'
I tried changing compileSdkVersion to 24 too, but nothing seems to work as of now. Actually everything was working fine before I introduced the play services library.
This dependency is using version 24.0.0 of com.android.support:animated-vector-drawable:
compile 'com.google.android.gms:play-services:10.2.0'
which will cause android studio to complain that it could lead to bugs/crashes because versions of all your google libraries don't match.
So you have 2 options: (that I know of off the top of my head)
Change your compileSdkVersion to 24 and change all your support library dependencies to version 24 as well to match the play-services dependencies:
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
Downgrade com.google.android.gms:play-services to 9.4 or 9.2.1 so that it doesn't use version 24 of anything. This still requires a minor change to your support libraries from 23.2.0 to simply 23.0.0
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.google.android.gms:play-services:9.4.0'

Android Studio: Gradle Sync fail with support-v4-24.1.1.jar

I am getting gradle issue .
here is below issue in gradle message, while doing sync in gradle
Our Android Studio version is 2.1.2.
Error:A problem occurred configuring project ':LetMeCall_Store'.
Could not find support-v4.jar (com.android.support:support-v4:24.1.1).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-v4/24.1.1/support-v4-24.1.1.jar
Below is gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.app.letmecall.store"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.0.0-beta1'
compile 'com.android.support:support-v4:24.0.0-beta1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.0.0-beta1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.loopj.android:android-async-http:1.4.6'
compile 'com.daimajia.androidanimations:library:1.0.3#aar'
compile "com.google.android.gms:play-services:8.3.0"
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:multidex:1.0.0'
}
Plz anyone help us to fix that issue
Advance thanks
I upgraded all my Android SDK tools (including "Support Repository"), however, I still got the error
Gradle sync failed: Could not find recyclerview-v7.jar (com.android.support:recyclerview-v7:24.1.1)
I then did the following :
targetSdk 24 (was 23)
buildToolsVersion: "24.0.3" (was 24.0.0)
deleted the folders within /.gradle/caches I have windows and the complete path is C:\Users\USERNAME\.gradle\caches
THEN the project built without error !!
Change this
compile 'com.android.support:design:24.0.0-beta1'
compile 'com.android.support:support-v4:24.0.0-beta1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.0.0-beta1'
to this
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
you have to use same version.
Replace with these
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.stackdemo"
minSdkVersion 11
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.0.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.loopj.android:android-async-http:1.4.6'
compile 'com.daimajia.androidanimations:library:1.0.3#aar'
compile "com.google.android.gms:play-services:8.3.0"
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:multidex:1.0.0'
}
I have the same issue and once i update Build tool version and android studio. Issue is resolved. Defiantly it is due to older build tool version.
I had this issue with a sample project from Android Developers. I updated all of the libraries in. the gradle file to latest versions then cleaned & rebuilt the project. All is working fine now.
Probably a good idea to make sure all of your sdk's are up to date too

Error in adding dependency in android

When I have following code gradle is build successfully.
ext {
supportLibVersion = '23.2.1' // variable that can be referenced to keep support libs consistent
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile 'pl.pawelkleczkowski.customgauge:CustomGauge:1.0.1'
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.wdullaer:materialdatetimepicker:2.3.0'
}
But when I added below dependency it stated giving me error.
compile 'com.afollestad.material-dialogs:core:0.8.5.9'
error
Error:Failed to resolve: com.android.support:appcompat-v7:23.4.0
Install Repository and sync project<br>Open File<br>Show in Project Structure dialog
Any suggestions.
Thanks
complete gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.zriton.udhaar"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext {
supportLibVersion = '23.2.1' // variable that can be referenced to keep support libs consistent
}
repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile 'pl.pawelkleczkowski.customgauge:CustomGauge:1.0.1'
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.wdullaer:materialdatetimepicker:2.3.0'
compile 'com.afollestad.material-dialogs:core:0.8.5.9'
}
You don't have the latest version of Google's libs installed. 23.2.1 should be 23.4.0.
The solution is at the bottom, "Install Repository"
Sounds like you need to install the "Android Support Repository" in the Android SDK Manager.
If you have the android tools on your path, just go to the Terminal and run:
$ android
You can also access it via Android Studio > Tools > Android > SDK Manager.
The support library that you are using is 23.2.1, but in error it is showing 23.4.0, replace your current version to 23.4.0 and try to sync project

my eclipse project error when migrated to android studio?

this my problem over day, my log result is Error:(2) Attribute "titleTextStyle" has already been defined
my project use actionbarsherlock, google_play_service, and another lib, i want to move my old project to android studio. i already tried many link in this site but doesn't work. this my gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.ltvie.test"
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
}
dependencies {
compile project(':lib')
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.code.gson:gson:2.1'
compile 'com.google.guava:guava:11.0.1'
compile 'com.google.protobuf:protobuf-java:2.2.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/google-api-client-1.10.3-beta.jar')
compile files('libs/google-api-client-android2-1.10.3-beta.jar')
compile files('libs/google-http-client-1.10.3-beta.jar')
compile files('libs/google-http-client-android2-1.10.3-beta.jar')
compile files('libs/google-oauth-client-1.10.1-beta.jar')
compile files('libs/jackson-core-asl-1.9.4.jar')
compile files('libs/json-org.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/universal-image-loader-1.9.3-SNAPSHOT.jar')
compile files('libs/WebSocket.jar')
}
i read some tutorial that my problem cause I use appcompat-v7 and actionbarsherlock in same time, but in my dependencies nothing appcompat-v7, i try to remove actionbarsherlock then the error disappear but appear more error. how to solve my problem, thanks.

Categories

Resources