`vectorResource` throws RuntimeException when ProGuard applies optimizations - proguard

I am using Jetpack Compose 1.0.0-alpha09 with Kotlin 1.4.21. I use vectorResource to load an ImageVector from resources.
All works fine in the design previews and for debug builds. However, when I build a release build with ProGuard, I get the following exception at runtime:
org.xmlpull.v1.XmlPullParserException: Binary XML file line #1<VectorGraphic> tag requires viewportWidth > 0
at androidx.compose.ui.autofill.AndroidAutofillDebugUtilsKt.vectorResource(AndroidAutofillDebugUtils.kt:142)
at ...
After a long tedious process trying to identify differences between release and debug which may cause this, I have discovered that disabling optimization in ProGuard using -dontoptimize 'solves' this issue.
What exactly causes this discrepancy in behavior? Is this a bug in, Jetpack Compose, ProGuard, or in my configuration of ProGuard?

Related

IntelliJ IDEA Not Showing Variables In Debug For Kotlin Main Script (main.kts)

I am running main.kts Kotlin script in a Kotlin console application project in IntelliJ IDEA. It runs fine, I can debug it too, but don't see any vars or vals defined further up in the script.
Message where the defined values/variables should be displayed is "Variables are not available". If I click around in the stack trace I can see other variables, such as the args that came in the main function of the Kotlin main script.
Any thoughts why declared values and variables cannot be seen in the debugger?
screenshot
MacOS 10.15.6 + IDEA CE 2020.3.1 + JDK adopt-openjdk-1.8 was the platform I experienced this problem upon, from where the screenshot came.
Windows 10 + IDEA CE 2020.3.1 + openjdk-15 did not experience this problem.
I fixed the problem by using adopt-openj9-15 with MacOS 10.15.6 + IDEA CE 2020.3.1. adopt-openj9-15 gives the warning for every main KTS run:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil (file:/Users/ducksnails/Library/Application%20Support/JetBrains/IdeaIC2020.3/plugins/Kotlin/kotlinc/lib/kotlin-compiler.jar) to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
JDKs openjdk-15 & adopt-openjdk-15 do no run or debug main.kts scripts, or kts scripts, at all on MacOS 10.15.6 + IDEA CE 2020.3.1. The run / debug button silently becomes disabled, hung, and unavailable.
For the now I'll use adopt-openj9-15 and try to ignore the constant warnings, but I would like to use a JDK that doesn't give the constant warnings, plus see the debug variables.

IntelliJ Kotlin/JS Mocha Unit Testing Unavailable via Plugin

I am experiencing some difficulty getting IntelliJ to recognize my Kotlin Tests as mocha tests and generating the green play button in the gutter allowing me to run Kotlin/JS unit tests in the IDE via the Mocha Plugin. Now, I somehow managed to get this working after some trial and error and then inexplicable earlier today it just stopped working and the green play buttons vanished from the gutter. I have tried all the normal stuff such as invalidating the IDE cache, removing .idea/*.iml files and reimporting project. Nothing seems to work.
Image of Working Environment
here is an image of the setup working as expected that I luckily took a snapshot of while I had the chance because I had so much difficulty getting it working.
You can also see that the mocha run configuration is accurately picking up on the fact that the actual file being ran is going to be the output file in my build directory.
My initial instinct led me to believe that this was due to IntelliJ picking up on my map.js files being generated as well, however this is not the case as did not (and do not) have my compile options set to with sourceMap = true or sourceMapEmbedSources = "always", as you can see from this snippet from my build.gradle.kts
compileKotlin2Js {
kotlinOptions {
moduleKind = "commonjs"
}
}
compileTestKotlin2Js {
kotlinOptions {
moduleKind = "commonjs"
}
}
For the record, my gradle build compiles and tests run successfully. To clarify, I am specifically trying to get IntelliJ to recognize the project structure in such a way that the run configurations can make these education decisions for me and speed up my workflow.

Instrumentation Error even if already Instrumented. (Standalone Instrumentation, using CaptainCasa Framework)

Even if Eclipse already said that class is instrumented, when I click "Reload Server" on CaptainCasa toolset, error occurs
org.javalite.activejdbc.InitException: you are trying to work with models, but no models are found. Maybe you have no models in project, or you did not instrument the models. It is expected that you have a file activejdbc_models.properties on classpath...
Here is the Instrumentation message from Eclipse.
Here is the error to make it more detailed.
the only reason for you to see this error is when your models are not instrumented. It is possible that your framework or an IDE wipes instrumented models and replaces them with non-instrumented.The message is self-explanatory.

Gradle TestListener logging

I've written a GradleTestListener (implements org.gradle.api.tasks.testing.TestListener) and registered this in build.gradle:
test { addTestListener(new com.abcd.GradleTestAdaptor()) }
This test listener uses a third party library which is printing a warning + stacktrace via Slf4J to the console. This is causing a lot of noise in the test output so I would like to suppress it. I have configured Slf4j & Log4J as dependencies on my project and placed log4j.xml with root level error in src/test/resources. The warning is still being printed so it appears my logging configuration is not being picked up.
I'm wondering, as the TestListener is part of the build (akin to a plugin), will it pick up my logging configuration? If not, make it so?

JNI UnsatisfiedLinkError- how do I load libraries correctly?

I'm trying to work with the Java sample Database program from the CardScan SDK.
I am working with files located in Java/JNI and Java/Database. The program must be run with a 32 bit JRE. I was able to do so on a 64 bit machine by uninstalling Java and installing the 32 bit version, then re-adding the system path for Java. I can run the program and interface with a CardScan database file (.cdb) successfully by double clicking the SDKData.bat file, but when I open the source files for editing and edit the Java.library.path to include the required library (CRTK_JNI.dll), I get UnsatisfiedLinkErrors everywhere:
Exception in thread "main" java.lang.UnsatisfiedLinkError: sdkdata.CRTK.CRTK_Init([I)I
at sdkdata.CRTK.CRTK_Init(Native Method)
at sdkdata.CRTK.(CRTK.java:239)
at sdkdata.SDKData.(SDKData.java:97)
at sdkdata.SDKData.main(SDKData.java:643)
Java Result: 1
Presumably this is happening because the library is not loading properly.
What do I need to do to run and edit the program at full capacity (with all the native functions from CRTK_JNI in working order)?
Presumably this is happening because the library is not loading properly.
On the contrary. The library load is complete. You aren't getting that from a System.load()/loadLibrary() call, you are getting the error when calling your native method, the one that should have the signature:
package sdkdata;
public class CRTK
{
public native int CRTK_Init(int[]);
}
So it isn't there, or you have changed the signature without regenerating the .h and .c files, or you have manually mangled the declaration some other way.
Post your code.
To clarify, this Java sample program is officially unsupported by the CardScan API - it was a bad idea to try to use the API with an unsupported language relying solely on an experimental implementation. I ended up using one of the supported languages (Visual Basic) to work with the SDK; if anyone looking at this question happens to be struggling with using the CardScan API, here is my VB implementation on Github.