Android test cannot find source class - android

I'm trying to configure a android app to run tests with robolectric.
I'm new to gradle, and I can't find out what the problem is.
When I run ./gradlew robolectric on the command line, I get a cannot find symbol error.
The error I get is:
MainActivityTest.java:18: error: cannot find symbol
Robolectric.buildActivity(MainActivity.class).get().getResources();
^
symbol: class MainActivity
location: class MainActivityTest
This is my build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'robolectric'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.app.id"
minSdkVersion 16
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
sourceSets{
main.setRoot('src/main')
androidTest.setRoot('src/test')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'org.robolectric:robolectric:2.3'
androidTestCompile 'junit:junit:4.11'
}
So, the problem seems to be that I cannot access the source file when I run the tests, but I couldn't find a way to fix it.
Can anyone tell me what i'm doing wrong?
Thanks!

main.setRoot('src/main') => Is it really a main folder / package in your project?
You can test again by using the fully file directory, ex: src/helloword/mainActivity.java

Related

Cannot resolve symbol error when importing OpenCv4Android in Android Studio

I want to use OpenCV4Android in Android Studio. I downloaded OpenCV for Android from this link:
http://opencv.org/downloads.html
But, when I try to import it, I get different errors in Camera2Renderer.java like, Cannot resolve symbol 'camera2', Cannot resolve symbol 'CameraDevice', Cannot resolve symbol 'Size', and Cannot resolve symbol 'CaptureRequest'.
I have tried both methods available here:
OpenCV in Android Studio
http://answers.opencv.org/question/14546/how-to-work-with-opencv4android-in-android-studio/
But, I get the same error.
Can anyone please tell me how to solve this error to be able to use openCV?
Thank you.
I faced the same issue while configuring OpenCV SDK with Android Studio.
I am using the latest SDK build of OpenCV : OpenCV-3.1.0-android-sdk
Please ensure that you have configured your build.gradle scripts.
Build.gradle(Module: app) -->
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.dev.opencvapp"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLib/'] } }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile project(':openCVLibrary310')
}
Build.gradle(Module: openCVLibrary310) -->
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
After doing this you should be able to build the app with out any errors.
I hope I helped you!!

Android Gradle Error - Illegal UTF8 string in constant pool in class

From one day to the other I opened the Android project that I'm currently working on and I got this gradle error, also happens when I try to create a new project:
Gradle sync failed: Illegal UTF8 string in constant pool in class file com/android/build/gradle/tasks/RenderscriptCompile$_ConfigAction_execute_closure7
Also I noticed that the arrangement of all the app packages has changed to this configuration and it is not able to import AppCompactActivity:
Error print screen
I had been trying to find something on the web but so far I found nothing related to this specific case. I tried a few things myself but I think it only made it even worse..
Anyone out there that can help me?
Thanks!
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "my.app.*****.musicpad"
minSdkVersion 14
targetSdkVersion 22
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:22.2.1'
compile 'com.android.support:design:22.2.1'
}
For anyone facing this error i have solved it by deleting the temp files.
Control panel-->Java-->Settings-->delete files and restore defaults.

error: cannot find symbol class Android Studio

This error hapens after update mac osx or system (I don't know).
It was after I open project that I closed one weak ago.
My settings.gradles is:
include ':app' , ':api', ':daogenerator'
project(':mobilneapi').projectDir = new File("/Users/AndroidstudioProjects/Modules/api")
project(':daogenerator').projectDir = new File("/Users/AndroidstudioProjects/Modules/daogenerator")
And my app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "pl.wm.myapplication"
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 project(':api')
compile project(':daogenerator')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
}
When I add import into MainActivity in Main Project.
I have got error after compile:
Error:(6, 24) error: cannot find symbol class Cache
What was wrong?
The same error on gradle build tools 1.3.0 and 1.2.4
try the usual stuff:
rebuild/clean project.
sync project with gradle files.
force close studio64.exe and restart it
restart the computer!
I hate these kind of errors, when nothing works, I usually end up creating a new project and start copying everything to it.

Unable to use github library in Android Studio

I want to use this library in a project in Android Studio, so as mentioned in read me, I created new project in the Android Studio and added dependencies in build.gradle file inside the app folder as:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.swipe_instagram"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.lorentzos.swipecards:library:1.0.8#aar'
}
Then when I sync I started getting this error as:
I have Searched on the google and stack overflow but can't find any appropriate solution.
I used your "build.gradle" file and it is working fine for me (both with and without "aar"). Could be something wrong with the cache. Try "File -> Invalidate Caches / Restart"). Another way to generate more error message detail is to try building the module from the command line and getting verbose output
gradle -info compileDebugSources
You'll get lots of output which should give you a hint as to what's going wrong

Gradle build fails in Android Studio

I am using Android Studio and created a new project, which created the standard "Hello world" mock.
My gradle.build file has the following contents:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.whatever.blabla"
minSdkVersion 19
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Even though I did not change anything, Gradle still fails when trying to build it with the error:
Failed to complete Gradle execution.
Cause:
A fatal exception has occurred. Program will exit.
First of all, is there any way of getting extra info about the problem? And secondly, why is this happening since I only created a standard project?
I had the same problem and could fix it by following solution provided in the below link -
https://code.google.com/p/android/issues/detail?id=67946
Though I am not sure how setting the maxheapsize has fixed the issue.

Categories

Resources