I use AS 0.4.2 then imported GMS as described in doc:
https://developer.android.com/google/play-services/setup.html
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v13:13.0.+'
compile 'com.google.android.gms:play-services:4.0.30' }
all what is detected by IDE is R class, but rest of code is invisible.
On the other hand I put following code:
import com.google.android.gms.common.GooglePlayServicesUtil;
(...)
private void connectGms(){
Log.d(MbcConstants.TAG,
"check for gms"+ GooglePlayServicesUtil.
isGooglePlayServicesAvailable(this));
}
And it works, but IDE still shows class name in red, but properly shows the params and returned type for method.
Ok - it seems like a bug in Android studio.
What I've done do fix it:
remove all dependencies (use F4 key) from project and the module
delete files from projectroot/.idea/libraries
open the module gradle.buld
add back all dependencies that are needed by your project to work. In my case:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
}
Synchronize gradle.build once again
Continue your adventure of love and hate or return to eclipse.
All you needed to do was hit the Sync Project with Gradle Files button after editing the build.gradle file by hand.
Related
since the last Update (of Android Studio ? or Gradle ?) I cannot import code from prod in my tests classes.
A few months ago, the tests were working without any problems.
I can launch the tests, using gradle in command line, or using AndroidStudio test runner. And it work nice : it passes when the code is ok, it fails when there is a bug.
But the auto-completion isn't working, the class, methods ... are red.
I cannot click on an object to navigate to the declaration ... and so on.
And the AndroidStudio automatic quickfix is : "add dependency on module xxx"
which add a line in the gradle file :
implementation project(path: ':app')
I have the same problem on several project, with gradle 6.1.1 or 7.2.1
AndroidStudio version is :
Chipmunk, 2021.2.1 patch 1
built on May 18 2022
the unit test, in app/src/test/java/com/apackage/ASimpleTest.kt
package com.apackage
import org.junit.Test
import kotlin.test.assertEquals
class ASimpleTest {
#Test
fun aTest(){
val plop = AClass()
assertEquals(1, plop.aMethod())
}
}
the class in app/src/main/java/com/apackage/AClass.kt:
package com.apackage
class AClass {
fun aMethod() = 1
}
I have no problem calling a method in the same folder as the tests.
The problem is test/main folder calling src/main
Android Studio 3.1.1. New module -> Import gradle project, after I select project to import and confirm, IDE crashes with exception:
Element: class org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl because: different providers: SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(1416c50); SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(665cfacf)
invalidated at: see attachment
com.intellij.psi.PsiInvalidElementAccessException: Element: class org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl because: different providers: SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(1416c50); SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(665cfacf)
invalidated at: see attachment
at com.intellij.psi.util.PsiUtilCore.ensureValid(PsiUtilCore.java:502)
Do you know any workaround?
I was facing the same issue, seems like IDE issue, try manually adding
include ':app', ':your_module_name'
in settings.gradle and sync gradle, hope it helps.
Below is how this issue manifests if you try to work in the kotlin REPL. However, you see the same issue more directly if you try to run a kotlin main fun from the IDE -- the kotlin classes are not on the classpath. Instead they are in .../app/build/tmp/kotlin-classes/debug. However, they do get put in the dex file.
I am looking at Kotlin for Android, and started with a very simple project (created freshly by Android Studio 3.1.1).
To learn kotlin I wanted to play with a simple .kt class converted from java.
After a rebuild, the Kotlin REPL is started, and this problem happens:
You’re running the REPL with outdated classes: Build module 'app' and restart
Welcome to Kotlin version 1.2.30 (JRE 1.8.0_152-release-1024-b01)
Type :help for help, :quit for quit
import hanafey.com.shoppy.Thing
val x = Thing("a", "b", "c", 1.0)
println(x)
error: unresolved reference: Thing
import hanafey.com.shoppy.Thing
In this case I ignored the "outdated classes" warning because it was not true.
So I believe the IDE and click the provided link to "Build module 'app' and restart". Now it claims another problem:
There were compilation errors in module app
Information:Kotlin: kotlinc-jvm 1.2.30 (JRE 1.8.0_152-release-1024-b01)
Information:4/14/18 7:49 AM - Compilation completed with 1 error and 0 warnings in 889ms
Error:Kotlin: Unsupported plugin option: org.jetbrains.kotlin.android:enabled=true
Am I wrong to think I should be able to fiddle with non-android related kotlin classes in the REPL?
When AS launches the kotlin REPL it includes the following directory in the classpath which contains the java files:
.../app/build/intermediates/classes/debug
However the kotlin classes are in:
.../app/build/tmp/kotlin-classes/debug
Either the gradle build is not putting the kotlin classes in with the java classes, or the kotlin repl is not started with all of the needed directories on the classpath.
If i understand correctly, the package hanafey.com.shoppy isn't included and therefore the unresolved reference.
:load /dir/path can be used to import all the packages in dir/path and the following should work.
val x = Thing("a", "b", "c", 1.0)
Could anyone help me out with the following error. When i clean the project, it doesn't show any error but every time i try to run i get this message.
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 2
The application was running with no errors but as my system crashed and restarted android studio i had few updates for Android API 22. After the update the application keep giving me this error message. I downloaded JDK 8 and tried to run but didn't work. Later i downgraded to JDK 7 after this stack post but still has not fixed it.
Is it possible to use Java 8 for Android development?
I have looked through numerous similar question but none works for me. Some similar issues found on stack were
why java.exe exit with value 1 in android studio
Error:Execution failed for task ':app:dexDebug'. > comcommand finished with non-zero exit value 2
Java finished with non-zero exit value 2 - Android Gradle
java.exe finished with non-zero exit value 2
Process 'command' C: \ Program Files \ Java \ jdk1.8.0_31 \ bin \ java.exe '' finished with a non -zero exit value 2
I have looked through dependencies in gradle built to see if there were any conflict but found none.
I even tried to copy the code into a new project and run it but still no success. Anyone who has faced the same issue and solved it please help me out.
After days of trying out finally could fix the issue. The problem with one of my .jar files. I had to remove each jar and check one by one until i found it. I removed the .jar file and cleaned my project and ran successfully. If any one should face similar issue check your jar file one by one.
I had the same error
app:dexDebug ExecException finished with non-zero exit value 2
i solve it by adding this line of code
defaultConfig {
multiDexEnabled true
}
The reason is that i was using too many libraries
Hope this post will help anyone
I had the same problem when I compiled google play services to my dependencies.
My mistake was I was compiling the enitre package like this
compile 'com.google.android.gms:play-services:8.3.0'
Instead when I tried the selective compile, it worked.In my case I was using for google sign in,so it had just had to be
compile 'com.google.android.gms:play-services-auth:8.3.0'.
More details are in the documentaion. https://developers.google.com/android/guides/setup#split
Hope this will be of a little help to someone someday :)
I know it's late.
But that's what actually worked for me.
1. Build > Clean Project
2. Close gradle daemon processes (ps -e| grep gradle //this will list gradle processes)
3. File > Invalidate caches & Restart
I hope this will work for everyone.
For future readers. If you're using your own AARs and upgraded one that has a shared dependency, you can also just try cleaning the project. In Android Studio "Build" -> "Clean Project".
This solved the issue for me, so I'd recommend giving it a quick try before you start digging for dependencies.
For me the solution was to remove an unnecessary/duplicate dependency entries. This is a similar solution others offered here that makes sense, but not exactly the same solution as those offered by others.
Since I was already including *.jar files in the list of files to be compiled, there was no need for additional entries in the dependencies list.
Before:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}
After:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
Remove
compile 'com.parse:parse-android:1.+'
add this linecompile fileTree(dir: 'libs', include: ['Parse-*.jar'])
Finally, it will look like this
dependencies {
compile fileTree(dir: 'libs', include: ['Parse-*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.android.support:design:22.2.0'
compile 'com.parse.bolts:bolts-android:1.+'
}
I had the same problem, just i did Biuld--> Rebiuld project and it works again ;)
I was using the robolectric dependency in my android project. I removed all robolectric dependencies in gradle and deleted all my robolectric tests, then I built the app and finally I could run the android project. Hope this can work for us.
I faced the same problem when trying to add the SignalR Java client library to my project's dependencies. I first changed the target JDK of my app from 1.8.0_XX to 1.7.0_XX, but it didn't work. Then I changed the SignalR project to target 1.7.0_XX as well, rebuilt and added it to my project's libs folder instead of the first build (which was in 1.8.0_XX), and that miraculously worked.
For me, the problem was that I was using different versions of "Google Play services sub API's"
Before:
Click to see the image
After:
Click to see the image
Check if there are 2 classes with same name. Each class name should be unique.
maybe for this issue you got means you added same liberay file in more than one time
Weird bug with Android Studio 2.2 when running a single test directly in IDE - I'll either have "No tests found" or run my previously compiled test.
Example:
#Test
fun testyTest() {
}
I'll create this test, and get the "No tests found". So I restart, and test is found! Obviously, the above test passes because it's empty. Next, I want my test to fail. So I manually throw an exception and add one line of code, below.
#Test
fun testyTest() {
throw RuntimeException()
}
Now I recompile, and this test passes too, because IntelliJ is for some reason has cached the previous test and reruns that. To get this test to properly fail - I must restart the IDE.
Anyone know what's going on? Note - I'm using Kotlin pretty heavily in this project.
EDIT 2: This is a JVM test (non-android, src/test/java) in an android library project.
EDIT: here's a full test class
package com.example.zak
import org.junit.Before
import org.junit.Test
class ExampleTest {
#Before
fun setUp() {
}
#Test
fun testyTest() {
//throw RuntimeException()
}
}
Found the fix...the issue only occurs when there's a variant selection conflict. Removing the conflict fixed the issue.
Check if you're have all these dependencies:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'junit:junit:4.11'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
Also as you're using Kotlin please disable entirely Instant Run in File -> Preferences.
EDIT: You're talking about tests in library - do modules and project has these dependencies and proper configuration.
It looks like after Gradle rebuilding, test works fine.
I found this bug description in the JetBrains IntelliJ bug tracking system. Here is the URL:
https://youtrack.jetbrains.com/issue/IDEA-149275
It discusses a change that was made to classloading that may impact Junit test execution. A workaround is suggested by adding a line to the options.xml config file. Here is an example workaround for Windows boxes - change as necessary for your platform. The version of Android below is the current 2.2 release:
1) exit Android studio
2) navigate to the config/options directory for your Android version:
e.g. C:\Users\YourNameHere\.AndroidStudio2.2\config\options
3) then add the "<property name="idea.dynamic.classpath.jar" value="false" />" line inside the component block of the options.xml file:
<component name="PropertiesComponent">
<property name="idea.dynamic.classpath.jar" value="false" />
Start Android Studio and try running local Junit tests.
I guess you use gradle in your project? I had the exact same problem and the solution was to use gradle to execute tests (inside the gradle task list) instead of using the menu (right click on the test file and run tests).