Robolectric tests fail in terminal, succeed in Android Studio - android

I've recently started to work on a new project, which includes Robolectric-based unit tests.
When ran from Android Studio (v3.6), all the tests pass successfully.
Strangely, some of the tests fail when I'm running them using ./gradlew test from terminal with very intimidating error:
java.lang.VerifyError: Stack map does not match the one at exception handler 56
Exception Details:
Location:
com/google/android/gms/measurement/internal/zzjy.zza(Landroid/net/Uri;)Landroid/os/Bundle; #56: astore
Reason:
Type 'java/lang/String' (current frame, locals[5]) is not assignable to null (stack map, locals[5])
Current Frame:
bci: #51
flags: { }
locals: { 'com/google/android/gms/measurement/internal/zzjy', 'android/net/Uri', 'java/lang/String', 'java/lang/String', 'java/lang/String', 'java/lang/String' }
stack: { 'java/lang/UnsupportedOperationException' }
Stackmap Frame:
bci: #56
flags: { }
locals: { 'com/google/android/gms/measurement/internal/zzjy', 'android/net/Uri', 'java/lang/String', 'java/lang/String', 'java/lang/String', null }
stack: { 'java/lang/UnsupportedOperationException' }
Bytecode:
// redacted..
Exception Handler Table:
bci [16, 53] => handler: 56
Stackmap Table:
same_frame(#6)
full_frame(#53,{Object[#2],Object[#145],Object[#129],Object[#129],Object[#129],Object[#129]},{})
full_frame(#56,{Object[#2],Object[#145],Object[#129],Object[#129],Object[#129],Null},{Object[#143]})
full_frame(#74,{Object[#2],Object[#145],Object[#129],Object[#129],Object[#129],Object[#129]},{})
same_frame(#104)
append_frame(#128,Object[#172])
same_frame(#143)
same_frame(#160)
same_frame(#177)
append_frame(#201,Object[#129])
append_frame(#225,Object[#129])
append_frame(#249,Object[#129])
append_frame(#273,Object[#129])
append_frame(#297,Object[#129])
full_frame(#300,{Object[#2],Object[#145],Object[#129],Object[#129],Object[#129],Object[#129]},{})
at com.google.android.gms.measurement.internal.zzfl.<init>(com.google.android.gms:play-services-measurement-impl##17.1.0:42)
at com.google.android.gms.measurement.internal.zzfl.zza(com.google.android.gms:play-services-measurement-impl##17.1.0:285)
at com.google.firebase.analytics.FirebaseAnalytics.getInstance(com.google.android.gms:play-services-measurement-api##17.1.0:9)
// redacted..
at org.robolectric.android.internal.AndroidTestEnvironment.lambda$installAndCreateApplication$0(AndroidTestEnvironment.java:276)
at org.robolectric.android.internal.AndroidTestEnvironment$$Lambda$45/1286999442.run(Unknown Source)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:75)
at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:276)
at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:169)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:301)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:243)
at org.robolectric.internal.SandboxTestRunner$2$$Lambda$28/968645498.run(Unknown Source)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
at org.robolectric.internal.bytecode.Sandbox$$Lambda$29/1700079137.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Why the tests pass in Android Studio, but fail in terminal?

Why the tests pass in Android Studio, but fail in terminal?
It's because there's a JDK version mismatch between the one that's used when invoked from Android Studio versus the one that's used when invoked from the terminal.
Which JDK version used by Gradle when invoked from the terminal?
When ran from terminal, Gradle uses a version defined in JAVA_HOME - which on my machine pointed to (older version) 1.8.0-51.
Which JDK version used by Gradle when invoked from Android Studio?
Starting from version 2.2, a copy of the latest OpenJDK comes bundled with Android Studio.
In example, Android Studio 3.6 uses OpenJDK v1.8.0-212.
The JDK version you want Gradle to use when running your tasks from Android Studio can be found/set at Project Structure > SDK Location > JDK Location. By default, it is configured to use the bundled OpenJDK version.
How did I solved the error?
In order to reproduce the errors in Android Studio, I've changed the JDK Location to JAVA_HOME, ran the tests (from Android Studio) again, and voila! the errors I've seen only in terminal now appear in Android Studio as well.
To resolve the failures I've seen when ran the tests from terminal, I've updated the JDK pointed by JAVA_HOME to latest (1.8.0-251), and now tests pass both in Android Studio and when ran using gradlew from terminal.

Related

Installing an app from Android Studio has timed out

Since we migrated to modules we started experiencing a time out when installing the application for the second time. It only happens if we run the app for the second time. If we clear the project (Build->Clean Project) it launches ok, but the next time we try to run, it times out.
I have looked at the Android Studio logs and found an error that is thrown when launching the app but I am not sure what could go wrong and how to interpret these logs. Here is the snapshot of the logs:
2021-01-19 12:26:15,790 [413000061] INFO - ools.idea.run.tasks.DeployTask - Installing application: *****
2021-01-19 12:26:15,792 [413000063] ERROR - intellij.openapi.progress.Task - entry
java.lang.NullPointerException: entry
at java.util.zip.ZipFile.getInputStream(ZipFile.java:361)
at com.android.tools.deployer.ApkParser.getApkDetails(ApkParser.java:88)
at com.android.tools.deployer.ApkParser.parse(ApkParser.java:107)
at com.android.tools.deployer.ApkParser.parsePaths(ApkParser.java:76)
at com.android.tools.deployer.ApkInstaller.deltaInstall(ApkInstaller.java:244)
at com.android.tools.deployer.ApkInstaller.install(ApkInstaller.java:91)
at com.android.tools.deployer.Deployer.install(Deployer.java:145)
at com.android.tools.idea.run.tasks.DeployTask.perform(DeployTask.java:119)
at com.android.tools.idea.run.tasks.AbstractDeployTask.run(AbstractDeployTask.java:119)
at com.android.tools.idea.run.LaunchTaskRunner.run(LaunchTaskRunner.java:191)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:932)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsync$5(CoreProgressManager.java:434)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$null$3(ProgressRunner.java:233)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:166)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:627)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:572)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:153)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:233)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2021-01-19 12:26:15,798 [413000069] ERROR - intellij.openapi.progress.Task - Android Studio 4.1.1 Build #AI-201.8743.12.41.6953283
2021-01-19 12:26:15,799 [413000070] ERROR - intellij.openapi.progress.Task - JDK: 1.8.0_242-release; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o
2021-01-19 12:26:15,799 [413000070] ERROR - intellij.openapi.progress.Task - OS: Windows 10
2021-01-19 12:26:15,799 [413000070] ERROR - intellij.openapi.progress.Task - Last Action: Run
2021-01-19 12:26:46,303 [413030574] INFO - j.ide.actions.RevealFileAction - Exit code 1
Please, help.
The issue was related to different versions of Android Studio and Android Gradle Plugin. When I had updated the Android Gradle Plugin version to the last available version the issue was gone. For more info see the posted issue in issue tracker.

LLDB exception after updating to Android Studio 3.1

After updating to Android Studio from 3.0.1 to 3.1, and updating all plugins and SDK tools i am no longer able to debug my native application.
The error is 'Execution finished' (ExecutionFinishedException) which is raised in LLDB.
LLDB version is 3.1.4508709 (which is the latest).
If i try and debug with an earlier version of LLDB i get an error LLDB is missing (or similar).
Error details:
Execution finished
com.intellij.execution.ExecutionException: Execution finished
at com.jetbrains.cidr.execution.ExecutionResult.get(ExecutionResult.java:38)
at com.jetbrains.cidr.execution.debugger.backend.lldb.LLDBDriver.getProtobufClient(LLDBDriver.java:90)
at com.jetbrains.cidr.execution.debugger.backend.lldb.LLDBDriver.executeConsoleCommand(LLDBDriver.java:1109)
at com.jetbrains.cidr.execution.debugger.backend.lldb.LLDBDriver.executeConsoleCommand(LLDBDriver.java:1103)
at com.android.tools.ndk.run.lldb.AndroidLLDBDriver.loadStartupScripts(AndroidLLDBDriver.java:321)
at com.android.tools.ndk.run.lldb.AndroidLLDBDriver.commonLoad(AndroidLLDBDriver.java:132)
at com.android.tools.ndk.run.lldb.AndroidLLDBDriver.loadForAttach(AndroidLLDBDriver.java:248)
at com.android.tools.ndk.run.AndroidNativeAppDebugProcess.prepareTarget(AndroidNativeAppDebugProcess.java:101)
at com.android.tools.ndk.run.AndroidNativeDebugProcessImpl.doLoadTarget(AndroidNativeDebugProcessImpl.java:123)
at com.jetbrains.cidr.execution.debugger.CidrDebugProcess.lambda$start$0(CidrDebugProcess.java:314)
at com.jetbrains.cidr.execution.debugger.CidrDebugProcess$MyCommandProcessor.consume(CidrDebugProcess.java:703)
at com.jetbrains.cidr.execution.debugger.CidrDebugProcess$MyCommandProcessor.consume(CidrDebugProcess.java:693)
at com.intellij.util.concurrency.QueueProcessor.lambda$null$0(QueueProcessor.java:93)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:246)
at com.intellij.util.concurrency.QueueProcessor.lambda$wrappingProcessor$1(QueueProcessor.java:93)
at com.intellij.util.concurrency.QueueProcessor.lambda$null$3(QueueProcessor.java:226)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:246)
at com.intellij.util.concurrency.QueueProcessor.lambda$startProcessing$4(QueueProcessor.java:226)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:315)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.intellij.execution.ExecutionFinishedException: Execution finished
at com.jetbrains.cidr.execution.debugger.backend.lldb.LLDBDriver$4.processTerminated(LLDBDriver.java:248)
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.execution.process.ProcessHandler$5.invoke(ProcessHandler.java:239)
at com.sun.proxy.$Proxy16.processTerminated(Unknown Source)
at com.intellij.execution.process.ProcessHandler$4.run(ProcessHandler.java:196)
at com.intellij.execution.process.ProcessHandler$TasksRunner.execute(ProcessHandler.java:272)
at com.intellij.execution.process.ProcessHandler.notifyTerminated(ProcessHandler.java:177)
at com.intellij.execution.process.ProcessHandler.notifyProcessTerminated(ProcessHandler.java:173)
at com.intellij.execution.process.BaseOSProcessHandler.onOSProcessTerminated(BaseOSProcessHandler.java:192)
at com.intellij.execution.process.OSProcessHandler.onOSProcessTerminated(OSProcessHandler.java:89)
at com.intellij.execution.process.BaseOSProcessHandler$2$1.consume(BaseOSProcessHandler.java:155)
at com.intellij.execution.process.BaseOSProcessHandler$2$1.consume(BaseOSProcessHandler.java:140)
at com.intellij.execution.process.ProcessWaitFor$1.run(ProcessWaitFor.java:66)
... 5 more
Last 2 lines from gdb-server log:
1522263876.330623627 NativeProcessLinux.cpp:MonitorCallback got exit signal(0x002EA90B) , tid = 25279 (is not main thread)
1522263876.330640793 NativeProcessLinux.cpp:MonitorCallback tid = 25279 handling non-main thread exit (%s)
Anyone else experienced this or know of a fix?
A workaround is to re-install Android Studio 3.0.1. This can be done alongside the latest version (see https://developer.android.com/studio/preview/install-preview.html).
For me, debugging c++ code then works again (in Android Studio 3.0.1) even though it is using the same versions of SDK tools (e.g. LLDB v3.1.4508709).

Error: Abnormal build process termination in Android Studio 2.0

This week I updated Android Studio to version 2.0. There is a known issue concerning Gradle, so I added export _JAVA_OPTIONS="-Djava.net.preferIPv6Addresses=true" to my ~/.profile (on Ubuntu 15.10).
But now I get this error when compiling:
Error:Abnormal build process termination:
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv6Addresses=true
Build process started. Classpath: /opt/android-studio/lib/jps-launcher.jar:/usr/lib/jvm/java-8-oracle/lib/tools.jar:/opt/android-studio/lib/optimizedFileManager.jar:/opt/android-studio/lib/ecj-4.4.jarError connecting to ::1:44484; reason: Protocol family unavailable: /0:0:0:0:0:0:0:1:44484
java.net.SocketException: Protocol family unavailable: /0:0:0:0:0:0:0:1:44484
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:454)
at sun.nio.ch.Net.connect(Net.java:446)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
at io.netty.channel.socket.nio.NioSocketChannel.doConnect(NioSocketChannel.java:210)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.connect(AbstractNioChannel.java:207)
at io.netty.channel.DefaultChannelPipeline$HeadContext.connect(DefaultChannelPipeline.java:1208)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeConnectNow(ChannelHandlerInvokerUtil.java:117)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeConnect(DefaultChannelHandlerInvoker.java:248)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:218)
at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeConnectNow(ChannelHandlerInvokerUtil.java:117)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeConnect(DefaultChannelHandlerInvoker.java:248)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:218)
at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47)
at io.netty.channel.ChannelHandlerInvokerUtil.invokeConnectNow(ChannelHandlerInvokerUtil.java:117)
at io.netty.channel.DefaultChannelHandlerInvoker.invokeConnect(DefaultChannelHandlerInvoker.java:248)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:218)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:212)
What can I do?
Use the opposite flag _JAVA_OPTIONS = -Djava.net.preferIPv4Stack=true

Installing Kotlin Android project fails with INSTALL_FAILED_DEXOPT

Attempting to run a Kotlin Android project using Android Studio compiles successfully and generates an APK, but when Studio tries to install the APK on the device the installation fails with INSTALL_FAILED_DEXOPT. Looking through logcat I can see messages similar to:
12-13 22:43:57.219: ERROR/dalvikvm(1623): Out-of-order method_idx: 0x2bff then 0x2bff
12-13 22:43:57.219: ERROR/dalvikvm(1623): Trouble with item 897 # offset 0x13e498
12-13 22:43:57.219: ERROR/dalvikvm(1623): Swap of section type 2006 failed
12-13 22:43:57.219: ERROR/dalvikvm(1623): ERROR: Byte swap + verify failed
12-13 22:43:57.230: ERROR/dalvikvm(1623): Optimization failed
The project was converted from Java using the Kotlin IDEA plugin's automatic conversion. There are no compiler warnings.
This occurs when a method name collides with a Kotlin-generated etter, for example:
class Foo(val bar: Any) {
fun getBar(): Any {}
}
Rename bar or getBar to something else. For more information see http://youtrack.jetbrains.com/issue/KT-3170
Recently the similar issue has been discovered on devices running api 17- with Kotlin 1.0.0-beta-1038.
To fix this issue use new beta build 1.0.0-beta-1103.
https://devnet.jetbrains.com/message/5561799#5561799

Xamarin Studio 2 - latest stable update - Error executing task Aapt: The source sequence is empty

I am using the trial version of Xamarin Studio for my final year project consisting an android application. Everything went smooth initially. But today right after updating to the latest stable version, i encountered an error (as stated on the title of this post).
The build log is as follows:
Building Solution: MyActivity.Mobile (Debug)
Building: MCAAndroid (Debug)
Build started 05/18/2013 17:04:44.
Project
"/Users/hazimanabhmy/Projects/MyActivity.Mobile/MCAAndroid/MCAAndroid.csproj"
(Build target(s)):
Target _CheckProjectItems:
CheckProjectItems Task
NativeLibraries:
JavaLibraries:
JavaSourceFiles:
Target _ComputeAndroidAssetsPaths:
ResourceFiles:
Assets/WebUI/newsfeed.html
Assets/WebUI/images/bg_content.png
Assets/WebUI/css/style.css
Assets/WebUI/images/flag.png
IntermediateFiles:
Target _GenerateAndroidAssetsDir: Skipping target
"_GenerateAndroidAssetsDir" because its outputs are up-to-date.
Target _ComputeAndroidResourcePaths:
ResourceFiles:
Resources/values/Strings.xml
Resources/drawable/Icon.png
Resources/layout/Login.axml
Resources/drawable/le_cool_logo.png
Resources/drawable/bg.jpg
Resources/drawable/icon_password.png
Resources/drawable/Icon_user.png
Resources/layout/Home.axml
Resources/drawable/info.png
Resources/drawable/settings.png
Resources/drawable/help.png
Resources/drawable/bg_content.png
Resources/drawable/shadow_black.9.png
Resources/drawable/cog.png
Resources/drawable/tools.png
Resources/layout/ReadMatric.axml
Resources/drawable/matric.jpg
Resources/drawable/mcalogo.png
IntermediateFiles:
Target _GenerateAndroidResourceDir: Skipping target
"_GenerateAndroidResourceDir" because its outputs are up-to-date.
Target _ResolveMonoAndroidSdks:
MonoAndroid Tools: /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/
MonoAndroid Framework: /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/android-10;/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1
MonoAndroid Binaries: /Library/Frameworks/Xamarin.Android.framework/Versions/Current/bin/
Android NDK:
Android SDK: /Users/hazimanabhmy/Library/Developer/Xamarin/android-sdk-mac_x86/
Java SDK: /usr/
Target _ValidateAndroidPackageProperties:
GetAndroidPackageName Task
ManifestFile: /Users/hazimanabhmy/Projects/MyActivity.Mobile/MCAAndroid/Properties/AndroidManifest.xml
AssemblyName: MCAAndroid
PackageName: MCAAndroid.MCAAndroid
Target _BuildDependencies:
Resolved library outputs:
Target _ExtractLibraryProjectImports:
Assemblies:
/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.dll
/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.Xml.dll
/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/android-10/Mono.Android.dll
/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.Core.dll
Jars:
ResolvedResourceDirectories:
Target _GetLibraryImports:
NativeLibraries:
Jars:
Target _CheckDuplicateJavaLibraries:
JavaSourceFiles:
JavaLibraries:
Target _UpdateAndroidResgen:
AdditionalResourceDirectories: /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:
error : Error executing task Aapt: The source sequence is empty Task
"Aapt" execution -- FAILED Done building target "_UpdateAndroidResgen"
in project
"/Users/hazimanabhmy/Projects/MyActivity.Mobile/MCAAndroid/MCAAndroid.csproj".--
FAILED
Done building project
"/Users/hazimanabhmy/Projects/MyActivity.Mobile/MCAAndroid/MCAAndroid.csproj".--
FAILED
Build FAILED. Errors:
/Users/hazimanabhmy/Projects/MyActivity.Mobile/MCAAndroid/MCAAndroid.csproj
(Build) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets
(_UpdateAndroidResgen target) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:
error : Error executing task Aapt: The source sequence is empty
0 Warning(s) 1 Error(s) Time Elapsed 00:00:00.1048310
---------------------- Done ----------------------
Build: 1 error, 0 warnings
I couldn't find the cause. Would someone help me?
I have asked this same question on Xamarin.Android's forum, and still waiting for their answer. But i think i could gather more resources and insights from experts here.
It's a recent change/bug in Xamarin.Android that expects to be used with Android tools rev. 22 or later where appt has been moved around in the sdk directory (from tools to build-tools). You need to go into the android sdk manager and update the SDK tools to revision 22 (or better) and also install the new build-tools package.

Categories

Resources