All libraries must have the exact version - java

I dont quite understand this my sdk version is the same as my 'appcompat' and 'recyclerview' but it still has an error to it,I have tried rebuild and clean the project but still geting the same result, I have the same project to this one but it doesn't have an error like this one, any idea whats going on here?
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.parasitologymemorization.parasitologymemorization"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar', '**/*.so'])
compile 'com.android.support.constraint:constraint-layout:1.0.2'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.github.satyan:sugar:1.5'
compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:recyclerview-v7:26.0.1'
compile 'com.beardedhen:androidbootstrap:2.3.2'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.wonderkiln:camerakit:0.12.0'
compile(name: 'tensorflow', ext: 'aar')
}

Android Studio makes a lot of files as caches and does not delete them. This can cause trouble when there is a need to make new files, so clearing 'cacheswill clear the oldcache` and make Android Studio faster.
So you need to Invalidate Caches/Restart in Android Studio.

Whichever versions it says are wrong in the error message, compile the newest version in your gradle file, even if you don't think you're using them. I've run into this multiple times and that always fixes it.
For example, you should manually compile the recyclerview dependency with version 27.0.0

Just copy the com.android.support:animated vector drawable:27.0.0" in the build.gradle file and then change 27.0.0 to 26.0.1 and that sync the gradle.

Related

Why android studio give an error when i add dependency?

I'm building a face detection Android app. When I add dependency inside the app/build.gradle it gives me an error. Here is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.android.emojify"
minSdkVersion 15
targetSdkVersion 28
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'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support ', module: 'support-annotations'
})
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-vision:10.2.0'
testImplementation 'junit:junit:4.12'
}
Error is reported in the following lines:
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
Show us a screenshot of your error or format your error to easier reading, just click code button and paste it.
Edit: thank you :)
I think you should use refresh gradle after any changes in gradle.build and maybe you got this error because your build tools sdk is 28.0.3 and you want to use tool from sdk 28.0.0, just change compile sdk to 28.0.0 and click sync gradle on actionbar.
Your buildToolVersion is greater than your design and appcompat-v7.
Try to change,
implementation 'com.android.support:design:28.0.3' //or greater than 28.0.3
implementation 'com.android.support:appcompat-v7:28.0.3' //or greater than 28.0.3
connect to the internet and then build your project. Problem will be solved.

after updating to api level 26 I get: java.lang.NoSuchMethodError: No static method getScaledHorizontalScrollFactor

I'm trying to update my app to use api level 26 and now I'm getting a very painful error when trying to start up the app. Here is the exception that seems to be causing it:
Caused by: java.lang.NoSuchMethodError: No static method getScaledHorizontalScrollFactor(Landroid/view/ViewConfiguration;Landroid/content/Context;)F in class Landroid/support/v4/view/ViewConfigurationCompat; or its super classes (declaration of 'android.support.v4.view.ViewConfigurationCompat' appears in /data/app/com.sprayme.teamrsm.analyticspraydown-2/base.apk)
My gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.sprayme.teamrsm.analyticspraydown"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:support-core-utils:26.0.2"
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:cardview-v7:26.0.2'
compile 'com.android.support:recyclerview-v7:26.0.2'
compile 'com.android.support:preference-v7:26.0.2'
compile 'com.android.support:support-v4:26.0.2'
compile 'com.android.support:design:26.0.2'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile('com.mikepenz:materialdrawer:5.9.5#aar') {
transitive = true
}
testCompile 'junit:junit:4.12'
}
If I set my compile and target versions back to 25 and the compile items back from 26.0.2 to 25.1.3 like I had them before, everything runs again.
I have searched high and low and haven't found anything that's helped yet. Anyone have any ideas?
Somewere in your classes or libraries you use the getScaledHorizontalScrollFactor method. This method is in the ViewConfigurationCompat class. According to Google, this class is deprecated in api 26. You have to use ViewConfiguration directly.
https://developer.android.com/reference/android/support/v4/view/ViewConfigurationCompat.html

Can't import: android.support.v7.widget.RecyclerView in Android Studio

I'm following my teachers tutorial and therefore writing exactly the same code that he has in his example. So I just created a new class to learn RecyclerView but I can't import RecyclerView On mouse-over, it just says "Cannot resolve symbol RecyclerView". I use Android Studio 2.3.3. Am I missing something obvious?
import android.support.v7.widget.RecyclerView;
public class CustomAdapter extends RecyclerView.Adapter<ComposedAdapter.Holder> {
//stuff
}
Gradle:
apply plugin: 'com.android.application'android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "sofialarsson.customrecyclerview"
minSdkVersion 19
targetSdkVersion 25
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.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
You need to add dependencies in build.gradle
Use this update gradle file
apply plugin: 'com.android.application'android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "sofialarsson.customrecyclerview"
minSdkVersion 19
targetSdkVersion 25
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.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.android.support:appcompat-v7:25.0.0"
compile "com.android.support:recyclerview-v7:25.0.0"
testCompile 'junit:junit:4.12'
}
Add below dependency in build.gradle;
compile 'com.android.support:design:xx.x.x'
If you are using androidx artifacts, add the following to your app level build.gradle
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
}
Might be useful, so Let me drop this for those who might want to migrate to androidx. In your build.gradle (Module app) add the dependency like this, instead of:
compile 'com.android.support:recyclerview-v7:23.3.0'
to
implementation 'androidx.recyclerview:recyclerview:1.1.0'
Then import like this, instead of:
import android.support.v7.widget.RecyclerView;
use:
import androidx.recyclerview.widget.RecyclerView;
Sync and enjoy!
Just add these two dependencies and you are good to go.
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
Make sure always always use same versions everywhere like you use here 25.3.1.
Also update your buildToolsVersion="25.0.0" .
Thanks!!!
Just add compile 'com.android.support:recyclerview-v7:25.3.1' dependencies in build.gradle app file like below code
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
}
Add below dependency in build.gradle
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta02'
Link Reference for latest releases
to give you an up-to-date and comprehensive answer, you have two choices.
Pre Android 9.0 (pre API 28), you have to use the old Support Library:
dependencies {
compile "com.android.support:appcompat-v7:25.0.0"
compile "com.android.support:recyclerview-v7:25.0.0"
}
For these dependencies, you have to use the version number of your Build Tools Version.
In Android 9.0 (API 28+) and above, you have to use the new Support Library (Noted here https://developer.android.com/topic/libraries/support-library/features#v7):
dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.recyclerview:recyclerview:1.1.0"
}
For these dependencies, you have to use the version numbers from the following pages:
https://developer.android.com/jetpack/androidx/releases/appcompat
https://developer.android.com/jetpack/androidx/releases/recyclerview
Add this class in the main_activity.xml file:
class="androidx.recyclerview.widget.RecyclerView"/>
Refer to https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView
for more info...

In Android studio 2.2.1 java.bean.* not found

I am trying to use opencsv library jar file but while importing i am getting the error message saying "Fail to load plugin descriptor from file *.jar".
I checked for META-INF/plugin.xml file inside the jar, but there is none.
So, i am now importing the source code of opencsv. I am getting error with java 7 api used within the library source code. All the usages of 'java.bean.*' package is giving 'cannot find symbol' error.
Following is the build.gradle file content:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.amadeus.jbisht.mytestproject"
minSdkVersion 23
targetSdkVersion 25
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(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.+'
testCompile 'junit:junit:4.12'
}
Please let me know what am I missing here. I can see it listed under 'External Libraries' but android studio isnt picking it up.
Gradle dependencies are the way to go:
compile group: 'com.opencsv', name: 'opencsv', version: '3.8+'
E.g.,
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile group: 'com.opencsv', name: 'opencsv', version: '3.8+'
}
Gradle will automatically import the required files and integrate the library.
opencsv need some java.bean libraries, but they are not included in the Android SDK.
To resolve this :
download sources of opencsv
download openbean
include both in your Android Studio project
replace java.bean.* dependancies by localpath.bean.* in opencsv sources

Pure Junit testing in Android studio

I've managed to setup a java test in my project however I've fallen into two different pitfalls.
1) I make a Java module, I can run it and do some arbitrary tests but since my Viewmodels/presenters/models are all in my Android project it means I cannot get the objects. That's a pretty big problem, I suppose an alternative would be to create a module for just the Presenters or ViewModels + Models.. but that seems bad
2) I make a folder under src/test/java/... however when I'm in there and try to compile, due to the lambda expressions in my project I end up getting weird compilation errors due to retrolambda.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.lang.invoke.MethodType not found
How do I go about setting up my gradle to testCompile in a way where Retrolambda isn't messing things up? Below is my gradle for the project
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
}
}
apply plugin: "net.ltgt.apt"
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "io.patrykpoborca.cleanarchitecture"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
encoding "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0'
testApt 'com.google.dagger:dagger-compiler:2.0'
//needed to resolve compilation errors, thanks to tutplus.org for finding the dependency
// http://stackoverflow.com/questions/27036933/how-to-set-up-dagger-dependency-injection-from-scratch-in-android-project
//test compiles
androidTestApt 'com.google.dagger:dagger-compiler:2.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.dagger:dagger:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.jakewharton:butterknife:7.0.1'
androidTestCompile 'com.google.dagger:dagger:2.0'
testCompile 'com.google.dagger:dagger:2.0'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.3'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'org.mockito:mockito-core:1.+'
androidTestCompile('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
}
}
P.s. does anyone know how to set a Java module's JavaVersion? In my java module Lambda's compiled despite being told that the version of java was wrong... really weird, here's the gradle of the java module. Thanks!
apply plugin: 'java'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
}
}
apply plugin: "net.ltgt.apt"
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'com.google.dagger:dagger:2.0'
testCompile project(':app')
}

Categories