I started to use AutoValue today in one of my projects and what bothers me is that Android Studio can not resolve the generated class name (AutoValue_DrawableContent) and marks it with the red color:
How I can suppress this warning?
Add the "idea" plugin to your build.gradle, for example:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.ltgt.apt'
With this plugin, Android Studio can find the generated source files.
you can just comment out each dependencies and sync one by one... it might get things fixed...
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Now that you have annotated your class, you need to build your project. This will generate the missing class, and Android Studio will be able to find it afterwards.
The build will not fail even though the editor is currently not recognizing the class name, because code generation will happen before the class is compiled.
Generate implementation class(es). AutoValue lib will do that.
Add these dynamically class(es) directory into source path. android-apt plugin will do this. After doing this, ide will know AutoValue_* and not to show errors.
Related
It pushes to upgrade Gradle plugin, but once I did it, the whole bunch of errors pop up.
It looks like my project build.gradle:
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
}
module build.gradle:
dependencies {
...
testImplementation 'junit:junit:4.+'
testImplementation 'org.mockito:mockito-core:2.4.0'
testImplementation 'org.powermock:powermock-core:1.7.0RC2'
testImplementation 'org.powermock:powermock-module-junit4:1.7.0RC2'
testImplementation 'org.powermock:powermock-api-mockito2:1.7.0RC2'
}
and gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
do not work anymore.
I tried to change them, but could not bring my powermock back.
What is the right combination of versions?
I'm getting an error in my implementation 'com.android.support:appcompat-v7:28.0.0' at build.gradle file after implementing implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I've already tried using
android.useAndroidX=true and
android.enableJetifier=true
Inside gradle.properties file but then I got another error in my MainActivity.kt file
Here's the error message :
Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='cardview-v7', myVersion='28.0.0', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.lifecycle', myArtifactId='lifecycle-viewmodel', myVersion='2.0.0', myPacking='aar', myClassifier='null'} incompatible dependencies less... (Ctrl+F1)
Inspection info:There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion). Issue id: GradleCompatible
Is there a way to fix this error? thank you!
AndroidX and Compat shouldn't be used together,AndroidX library was introduced to remove Compat Libraries.
Turn off
android.useAndroidX=false and
android.enableJetifier=true
Post your complete app gradle file. There is a library in your dependency that is using a version lower than your targetSdkVersion.
I have this in my build.gradle(module:app) :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-
layout:1.1.3'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:gridlayout-v7:28.0.0'
}
and when I try to sync it displays this:
ERROR: Manifest merger failed : Attribute application#appComponentFactory
value=(android.support.v4.app.CoreComponentFactory) from
[com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0]
AndroidManifest.xml:22:18-86 value=
(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to
<application> element at AndroidManifest.xml:9:5-32:19 to override.
what can cause this and how do I fix it?
(adding tools:replace="android:appComponentFactory" to the manifest doesn't work)
Your android-image-cropper library is using androidx, while you haven't migrated yet. It is highly recommended to migrate to using Androidx, since most of the libraries are doing the same and may not provide backward compatibility to the com.android.support variants.
If you cannot migrate in the short term, then you can revert to a lower version of the library. As per the changelog, they migrated to AndroidX in 2.8.0, so you should go back to 2.7.0.
I have updated my Android studio to 3.2.1 since then am getting error as below
Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.android.support:appcompat-v7:28.0.0.
hence unable to build my application
I have unchecked offline too
my dependencies in gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
kindly suggest a solution for this
Regards.
Nagendra
I think you are using old version of build tool in project level build.gradle.
Try
classpath 'com.android.tools.build:gradle:3.2.1'
Update your Android Gradle plugin
1- Upade the classpath in top-level build.gradle to:
buildscript {
....
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
2- Update the Gradle version to 4.6 in the gradle-wrapper.properties file by changing the distributionUrl to:
...
distributionUrl = https\://services.gradle.org/distributions/gradle-4.6-all.zip
...
3- Go to ReBuild Project
classpath 'com.android.tools.build:gradle:3.2.1'
add this to the dependencies of buildscript. then Sync the project.
Thanks for the response,
Isuue was with proxy blocking the downloads,i have commented the proxy in gradle.properties then its started working, i was trying in the office network.
Regards.
Nagendra
I try to use Mockito from within Android Studio 1.2.2 but I get the following error:
Error:(50, 17) Failed to resolve: org.mockito:mockito-core:1.10.19
The error occurs when I sync Gradle after adding the dependency manually. This is the dependency in my module Gradle file:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
testCompile 'org.mockito:mockito-core:1.10.19'
}
Could anyone help my resolve this issue?
Related questions:
Do I first need to download Mockito manually?
If so, where should I put it?
Note: the comments were helpfull to solve the above problem. However, it got me into another problem which I could not solve. But updating to Android Studio 1.3 solved it. I am now running Mockito from within Android Studio.
Try replacing testCompile with androidTestCompile, it works for me when importing Mockito libs.
However, you may run to a runtime error if you include only mockito-core. You'll need to add into your gradle:
androidTestCompile "org.mockito:mockito-core:1.10.19"
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"
If you have error with dexcache, put this line into your setUp() (Assuming you are using InstrumentalTestCase)
System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());
I was stuck into a similar problem, and adding the mockito jar file manually did the thing for me.
To do that, first create a directory called "libs" in your app directory. Take note that this directory should be in the same level as that of the src/main and build directories.
Next, download the mockito jar file and paste it into the libs directory.
Include that into your dependencies in the app level build.gradle file:
dependencies {
compile files('libs/add-your-jar-file-name-here')
}
Sync the gradle and that should do the job.
Refer to this answer for more detailed answer with snapshots.
androidTestCompile has now been replaced with androidTestImplementation
dependencies {
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
}
Make sure the test file is located under $your_module/src/test/java or $your_module/src/androidTest/java directory.