Cannot resolve symbol AndroidJUnit4 - java

I'm trying to add loginfacebook for my app. But when I added a repository that is need in doing this. It caused an error. The AndroidJUnit4 cannot resolve now.
ExampleInstrumentedTest.java
package com.example.user.enyatravelbataan;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* #see Testing documentation
*/
#RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
#Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.example.user.enyatravelbataan",
appContext.getPackageName());
}
}
and this is my build:gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
useLibrary 'org.apache.http.legacy'
repositories {
mavenCentral()
}
defaultConfig {
applicationId "com.example.user.enyatravelbataan"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(name: 'wikitudesdk', ext: 'aar')
// compile 'org.apache.httpcomponents:httpclient:4.5'
// compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile files('libs/MD5Simply.jar')
compile files('libs/GenAsync.1.2.jar')
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services:9.8.0'
compile 'com.google.android.gms:play-services-location:9.8.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:24.2.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
}
repositories {
flatDir {
dirs 'libs'
}
}
apply plugin: 'com.google.gms.google-services'

Try
androidTestImplementation 'com.android.support:support-annotations:23.1.0'
androidTestImplementation 'com.android.support.test:runner:0.4.1'
androidTestImplementation 'com.android.support.test:rules:0.4.1'
Add following above dependencies section
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
}

In addition to the above answer please ensure you follow these steps strictly:
I was banging my head against the wall and/or any object i see in front of me in order to make my SQLite function unit tested. No matter what I do, how strictly follow the suggestions provided my many wise people all over the internet did not work.
I then had to go to preschool and start over to realize my stupid mistake. I learned that AndroidJUnit4 can only be used with Instrumentation Test and JUnit must be used for local tests. That being said, the folder must be src/androidTest/java. I had my test class directly under androidTest folder, hence I had to face that nasty error. However, the moment I moved it under src/androidTest/java everything went very clear like "I can see clearly now the rain is gone".
Take a look at this article which says...
Run Instrumented Unit Tests To run your instrumented tests, follow
these steps:
Be sure your project is synchronized with Gradle by clicking Sync
Project in the toolbar. Run your test in one of the following ways:
To run a single test, open the Project window, and then right-click a
test and click Run . To test all methods in a class, right-click a
class or method in the test file and click Run . To run all tests in a
directory, right-click on the directory and select Run tests . The
Android Plugin for Gradle compiles the instrumented test code located
in the default directory (src/androidTest/java/), builds a test APK
and production APK, installs both APKs on the connected device or
emulator, and runs the tests. Android Studio then displays the results
of the instrumented test execution in the Run window.
Therefore folks, for instrumentation test the folder must be (do not forget the case)
src/androidTest/java
and for local tests the folder must be
src/test/java
You can then have your package folder(s) to match your app package
Hope, this helps for the community!

If this issue is coming after migrating to AndroidX. Do this:-
1. Correct imports
import androidx.test.runner.AndroidJUnit4
instead of
import android.support.test.runner.AndroidJUnit4
2. Correct method
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
instead of
Context appContext = InstrumentationRegistry.getTargetContext()

Another important thing (that has surfaced this issue for me) is to check if you have changed the build type for tests - that would be the testBuildType option in your module's build.gradle.
If you did change it (like I have), then before editing any Android tests:
Go to your Android Studio build/flavors tab
Select the same build type you specified in your testBuildType Gradle property
Sync Android Studio with Gradle
To run the app normally again, you would obviously need to switch back to 'debug' I suppose.
Note: Even though this fixes my core issue as described by the question here, I'm still looking for a way to support both custom build types for Android tests, but also allow debug build types; my ultimate goal is to have CI running the tests with a special build type, but let developers run them in 'debug' mode. So if anyone has an idea on how to accomplish that, the comments section is yours. :)

Just add compile "com.android.support.test:runner:1.0.1" to your Gradle.

For me it was because some of the androidTestImplementation imports were not up to date in build.gradle. After I updated them all to the newest version, the error was gone.
Note:
My project had multiple modules and I had to update them in every module.

Please try the latest API like following
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-ore:3.0.2'
still, No luck then try "implementation" instead of testImplementation, androidTestImplementation and androidTestImplementation and sync in Gradle.

the solution that worked for me is changing the emulator (one that uses the api you are using)
To do that click on the symbol of the emulatr next to the Run button (ex : Pixel 2)
then go down to Open AVD Manager (add the api u need (ex API 29))
Thats all

Related

Gradle sync failed: Could not find com.android.tools.build:gradle:3.6.2 issue

I found an old android project from github but I can't run it. It gives me a lot of errors.
like
9:13 PM Gradle sync failed: Could not find com.android.tools.build:gradle:3.6.2.
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.2/gradle-3.6.2.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.2/gradle-3.6.2.jar
Required by:
:Android-Hospital-Management-Client-master:unspecified
Consult IDE log for more details (Help | Show Log) (8 s 451 ms)
I thought it because that not update the dependencies and I change compile to implementation like this and update all the dependices like the below.
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.shivam.openmrs"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible,GradleCompatible
implementation 'com.android.support:appcompat-v7:22.1.1'
implementation 'br.com.liveo:navigationdrawer-material:1.0.5'
implementation 'com.rengwuxian.materialedittext:library:1.8.2'
implementation 'com.github.navasmdc:MaterialDesign:#aar'
implementation 'com.afollestad:material-dialogs:0.6.2.4'
implementation 'com.parse.bolts:bolts-android:1.5.0'
implementation fileTree(dir: 'libs', include: 'Parse-*.jar')
implementation fileTree(dir : 'libs', include: 'commons-lang3-3.4.jar')
implementation fileTree(dir : 'libs', include: 'commons-io-2.4.jar')
implementation 'com.getbase:floatingactionbutton:1.5.1'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.jjoe64:graphview:4.0.1'
implementation 'com.github.PhilJay:MPAndroidChart:v2.1.0'
}
This is a photo of that error um getting after run it.
Error:
.
How I fix this and run it ?
Change the gradle version to newer version such as 4.0.2 in build.gradle and sync project
please try it
Click File > Settings (on macOS, Android Studio > Preferences ) to open the Settings dialog.
In the left pane, expand Build, Execution, Deployment and then click Gradle .
Under Global Gradle settings, uncheck the Offline work checkbox.
Click Apply or OK for your changes to take effect.
It would definitely give a lot of errors because your android studio configuration is too different from any other project configuration.
It also happens with me many times. If I found one error then more other errors came out.
but I solved the way to get out of here
The main stuff to run the projects is the XML and Java and little bit of drawable and value.
So just copy all of that and paste into your project Because this stuff doesn't get changed with time.
I hope it would help you
And if it is much important to you so you would definitely do the steps given.
So, have a nice day!!!
Stay learning, Stay safe
:)
Please find this panel at the left of Android Studio to check offline mode
Please click on sixth logo
After this please run following command to clear gradle cache:
rm -rf ~/.gradle/caches/
after that please click on Invalidate Caches/Restart from File menu then further processing will happen which downloads all the libraries again so it takes time but also resolves this issue.

More than one file was found with OS independent path 'META-INF/androidx.legacy_legacy-support-core-utils.version'

I added BottomNavigationView and then things started to complicate. I don't know what's causing this error, when I build project it's okay but then when I want to play app in emulator - this error pops up.
Here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.pokrz.x"
minSdkVersion 22
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'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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.parse:parse-android:1.16.3'
implementation 'com.google.android.material:material:1.0.0-beta01'
}
repositories {
mavenCentral()
}
I don't know what else I can do. I'm sooooo done with it.
Build > Clean Project helped me.
Add a new exclude line with the path that is causing the error :
exclude 'META-INF/androidx.legacy_legacy-support-core-utils.version'
This message appears when upgrading Android Studio and has to do with Gradle Plugin Version and Gradle Version. I've seen the error with:
Android Gradle Plugin Version 3.6.2
Gradle Version 6.3
Build: Generate APK Debug
However, build was OK when generating the APK Release. More importantly, it was OK too by switching the Android Gradle Plugin Version to 3.5.0, 3.6.0, 3.6.1... and then rebuilding. Finally, it worked again well with 3.6.2 (latest version as of this writing) after switching once or twice the plugin version.
So, just play with it until you reach a combination that works. Further, try back the latest plugin version, as it seems to be just a bug of Android Studio when upgrading.
(Conclusion: No need to add 100 exclude statements in your build.gradle)
Actually the same Error Was happenimg with me also ...
and By just Re-Starting my Android Studio it solved....
Today, I was having the same problem. Below solution did not work for me
Clean the project
Invalidate case and restart
I solved that by deleting the folder. If you are facing this problem via creating release build then delete release folder and if you are facing this problem via creating debug build then delete debug folder. And now you are good to go. Now you can create signed APK.
It may help others.
Two ways to solve it
1- first
. Click on Specific project in android Studio
. Build
. Clean Project
. Run again
. Click **file**->**Invalidate Caches** /Restart
2- Second
Go to android project's in any disc you can store apps
Delete bothe folder
->debug
->release

FireBase Error: cannot access zzanb class file for com.google.android.gms.internal.zzanb not found

UPD. I have read these question and answer (Class file for com.google.android.gms.internal.zzaja not found). But I doesnt understand what strings i need to add or remove in my project.
Because I havent this and other strings in my code:
compile 'com.google.android.gms:play-services-location:9.2.0'
I develop an android app with use of FireBase. And when I want to build my project I have an error:
Error:(39, 25) error: cannot access zzanb
class file for com.google.android.gms.internal.zzanb not found
The error was caused by invoking statement: FirebaseAuth.getInstance().getCurrentUser();
Projects build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Modules build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "xxx.yyy.zzz"
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(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.firebase:firebase-core:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.1.0'
compile 'com.firebaseui:firebase-ui:0.6.0'
compile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
apply plugin: 'com.google.gms.google-services'
Please, help me to solve that error)
P.S I have already read that question (Firebase Error cannot access zzanb after using play-services-xxx:9.8.00), but i didnt understand anything, what i need to add or remove from my build.gradle files in my situation.
You're mixing libraries from old and new Firebase released. Everything from Firebase that you use should be in parity. This line is reference an library from a very old Firebase release (before it became the Firebase platform at Google):
compile 'com.firebaseui:firebase-ui:0.6.0'
If you want to use the Firebase-UI library, you should use the new version of it that matches the version of the main client library you're using. You're using 10.0.1, so according to the table on the Firebase-UI github I just linked, you want this dependency:
compile 'com.firebaseui:firebase-ui:1.1.1'
Always make sure your Firebase-UI library matches the core Firebase SDK you're using.
It looks like in your case Doug's fix resolved your issue, but we recently encountered the same problem with a different root cause.
In our case, we had configured our IDE project to use JDK8 but failed to check which version of the JDK was in use in the terminal. Because React Native runs Gradle from the command line when you type 'react-native run-android' Gradle was attempting to build using JDK10 which caused obvious issues since Android currently only supports up to JDK8. Once we configured the terminal to use JDK8 the issue was resolved.
TL;DR: Check what version of the JDK you are using in the terminal.
Getting following error:
error: cannot access zza
class file for com.google.android.gms.common.internal.safeparcel.zza not found
dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-analytics:17.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
/* implementation 'com.google.firebase:firebase-core:9.2.0' // this line must be included to integrate with Firebase
implementation 'com.google.firebase:firebase-messaging:10.2.1' // this line must be included to use FCM*/
//implementation 'com.google.android.gms:play-services:10.2.1'
implementation 'com.google.android.gms:play-services-maps:10.2.1'
implementation 'com.google.firebase:firebase-core:10.2.1'
implementation 'com.google.firebase:firebase-messaging:10.2.1'
}

Android Studio project setup for Espresso tests

About a week ago I asked this question
Why is library module android.support.test not visible in add dependency
After much head scratching and project setup morphing I discovered that this app/build.gradle dependency configuration gets me so much further than ever before in that at least the project compiles but does not build when attempting to run:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.my.package.name"
minSdkVersion 8
targetSdkVersion 22
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets { main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] } }
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:support-v4:22.1.0'
compile 'com.android.support.test.espresso:espresso-core:2.1'
compile 'com.android.support.test:testing-support-lib:0.1'
}
Notice compile instead of androidTestCompile on the testing support dependencies. Using androidTestCompile results in the problems noted in my previous question identified above.
Also notice the two srcDirs in the sourceSets declaration. That declaration was automatically set when I manually created the androidTest/java directory. Should this be declared differently?
Also too, getDefaultProguardFile is underlined in the ide with the tool tip "cannot resolve symbol 'getDefaultProguardFile'". In case that is crucial.
This new revelation, switching androidTestCompile to compile, leads me to believe there is something wrong with the way I set up the project structure for the unit test. Here is a picture of my project structure:
I should mention that this project/module structure was automatically created when migrating from Eclipse. By the icon decorations it looks like it at least recognizes my test class as a test class.
But now I am stuck at this error:
Error:Execution failed for task ':mymodule:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\myuser\AppData\Local\Android\sdk\build-tools\22.0.1\dx.bat --dex --no-optimize --output C:\Users\myuser\AndroidstudioProjects\myproject\mymodule\build\intermediates\dex\debug --input-list=C:\Users\myuser\AndroidstudioProjects\myproject\mymodule\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/test/BuildConfig;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Not sure if this is coming from my project setup or if it is coming from the libraries due to using compile on the support.test libraries.
Any advice on why androidTestCompile doesn't work is appreciated.
Also I just 2 days ago took all the latest updates from SDK Manager to 22.0.1 to no avail.
Another thing I noticed is the only jar I seem to find containing package com.google.common.* is in the espresso library. (com.google.common.* is a dependency of the testing libraries.) But when I inspect the espresso library jar with winzip all of the com.google.common.* package folder structure is there but there are no .class files in the package folders nor subfolders. Just mentioning that in case it lends a clue. Perhaps it is somewhere else also that I had missed.
Thanks!
Edit:
my source sets now look like this
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
}
and dependencies
dependencies {
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:support-v4:22.1.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}
I still get can't resolve android.support.test in my test class (test is colored red on these lines):
import android.support.test.InstrumentationRegistry;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
shouldn't I see a testing-support, espresso-core and espresso-contrib in my External libraries?
Below is my working Espresso gradle setup based on Android Studio 1.1.0 + Espresso 2.0 + Support Library v11 + gradle environment. It looks likely that you missed androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0' library.
dependencies {
// ...
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}
android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
packagingOptions {
//...
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['res']
}
}
}
About the directory, yes. just maintain androidTest and main under src folder. But, your setting does not make IDE to recognize androidTest folder as a test project folder. For that, two projects with same package name causes multi dex error I think. Use androidTestCompile to espresso-related lines in gradle dependencies and clean/rebuild project.
Note that you have to set all referenced projects gradle to same testInstrumentationRunner.
I also spent times to make it work. I wrote Korean tutorial to setup and run Espresso. Sorry about the language but screenshots might be helpful or you can try Google translate to read it.
EDIT. APPENDED BELOW
I thought why your IDE did not show green color in androidTest folder (means Test Project), and found your gradle setup seems to be wrong.
The line
{ main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] } } make IDE to recognize androidTest is a Project folder not Test Project folder. remove second one. androidTest will be automatically recognized as a Test Project.

Android Studio not detecting support libraries on Compilation

Since Android Studio is going to be default IDE for Android Development, I decided to migrate my existing project into Android-studio. The project stucture seems different and the hierarchy of folders in my Project is as follows:
Complete Project
->.idea
-> build
-> Facebook SDK
-> MainProject
-> ... (Other Libraries)
build.gradle
local.properties
settings.gradle
...
External Libraries
-> Android API 8 Platform
-> Android API 18 Platform
-> Android API 19 Platform
-> 1.7 Java
-> support-v4-19.1.0
My MainProject has a libs folder which contains different jars used within the project. It surprisingly does not contain the android-support-v4 jar which was present in my eclipse project. So, it seems that the external Libraries folder at the root must take care of it.
But after import, when I tried to compile the project started throwing "Symbol not found error" for Certain Classes all relating to android support library.
For Eg: The auto complete in Android Studio gives me suggestion for NotificaitonCompat from android.support.v4.app.NotificationCompat, but when I try to compile my Project Module it says
Error:(17, 30) error: cannot find symbol class NotificationCompat Error:Execution failed for task ':app:compileDebugJava'.> Compilation failed; see the compiler error output for details.
This happens in many other classes too for the same support library. I tried to insert a jar and changed the same in the build.gradle for the MainProject, but the error persists.
I even tried restarting and building the project again, but nothing changed.
EDIT:
I am attaching the Gradle file inside the MainProject
build.gradle in MainProject Module
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "package.app"
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
dependencies {
compile project(':facebookSDK')
compile project(':library')
compile project(':volley')
compile 'com.google.android.gms:play-services:+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:19.1.0'
compile files('libs/FlurryAnalytics_3.3.3.jar')
compile files('libs/universal-image-loader-1.8.4.jar')
....
}
This part of your build file:
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
is telling the build system to ignore support-v4, which is why it isn't compiling. Remove that.
In your build file, you have this, which is the correct way to include support:
compile 'com.android.support:support-v4:19.1.0'
If you have the support library jar file in the libs directory of any of your modules, remove it and make sure you refer to it this way -- if you include the library as a jar, you're likely to run into a problem where the jar is included multiple times which will result in a dex error.
If you have jar files in a 'libs' directory, you can specify it in you build.gradle file :
dependencies{
compile fileTree(dir: 'libs', include: ['*.jar']
compile 'com.android.support:support-v4:21.0.3' //to automatically add up-to-date support lib
}
Hope this helps!

Categories

Resources