I got a blocker when trying to convert existing simple android app writing in kotlin to KMM.
Below is the following error.
Please initialize at least one Kotlin target in 'kmmsharedmodule (:kmmsharedmodule)'.
Read more https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets
Unresolved reference: iosSimulatorArm64
I read the documentation provided in the link but seems not a direct solution to what i wanted.
The process i took was just by adding KMM module through provided support in android stuido.
I've looked for others sources but i couldn't find any related problems
Update your compose version to 1.0.3 then you can set Kotlin Compiler Version to 1.5.30 . Now iosSimulatorArm64 will work fine as it was introduced in version 1.5.30
Related
I am looking for answers related to Autofindviews nuget and its compatibility.
As per this link [AutoFindViews Nuget] (https://www.nuget.org/packages/AutoFindViews/) under framework I could see they mentioned the product version as MonoAndroid10.
Does that mean this nuget will support for Android projects targeting till Android10?
If it supports till Android 10, I am facing an issue where it gives below error while trying to migrate the Xamarin.Android project from Android 9 to Android 10 (Where the packages are updated to AndroidX and Support widgets in layout files are changed to androidx )
Error CS0246 The type or namespace name 'Androidx' could not be found (are you missing a using directive or an assembly reference?)
Can anyone please help me understanding this? Thanks in Advance
Bro, at Google I/O 2018, the Android team announced AndroidX, but the Autofindviews nuget which is just used to replace the FindViewById method last update at the 2017. So It can't find the view in the AndroidX library.
So you can try the three solution :
Remove the reference of the Autofindviews nuget and do the FindViewById by yourself.
Have a mixed use between the Support Library and the AndroidX Library. Only use the view which belongs to the Support Library in the xml. You can also use Support Library in the Android 10.
Try to use another nuget package, such as xamarin.androidx.viewbinding.databinding 4.1.2.
Is there a way to find duplicated (Copy/pasted code, repeated code) Kotlin code in Android Studio?
I have Android Studio 4.0 but can't find this "Duplicated code fragment" option.
Are there any Android Studio plugins that do this job for Kotlin?
You can install the sonarLint plugin.
It has many rules which are executed on source code to find possible issues like bugs or code smells.
This is done with the rules provided by default.
Other example of repetition:
Just need to install the sonarLint plugin in Preferences/Plugins:
A more advanced tool you could check is Gradle CPD plugin.
This is a Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD). You can find information about how to install it and how to use it in the same readme of the repository. CPD supports Kotlin since v6.10.0.
I am building an app that will rely heavily on user data and plan on using Room to help manage and store their information. However, while following a tutorial I ran into a few versioning issues that I was having troubles resolving on my own.
Since I am fairly new to both Android development as well as using Room, I have been following this tutorial: Android Room with a View - Kotlin
I first noticed there might be some issues in step 3 when I updated my Gradle files. I was met by the following error on the last two lines of the dependencies block:
Library should be updated to be compatible with Kotlin 1.3
I was confused by this since the tutorial uses a variable of some kind to determine the library versions. I ran the app at this point and it seemed to work fine so I continued.
When I got to step 9, I also ran into additional errors which now prevent builds from completing:
Type mismatch: inferred type is kotlin.coroutines.experimental.CoroutineContext but kotlin.coroutines.CoroutineContext was expected
Type mismatch: inferred type is kotlin.coroutines.CoroutineContext but kotlin.coroutines.experimental.CoroutineContext was expected
This is on top of errors that implementations of kotlinx.coroutines.experimental are obsolete, however, I couldn't find references to libraries without experimental using Android Studio's intellisense.
What do I need to do in order to resolve these library issues and allow me to continue the tutorial?
To the best of my knowledge, here is the recommended way to resolve these issues.
To try and solve these issues, I started with the errors in my Gradle scripts to see if that would maybe resolve dependencies in the code. I did find this post, which I'm still not completely convinced is the best solution, but just following the first couple of suggestions in the top answer did clear most of my issues.
To be clear, I changed the following:
Changed the variable in the last line of the dependencies Gradle block to have a hard-coded version number (I did the latest as found in the kotlinx.coroutines repo). If possible, I would like this to be auto-generated again as the tutorial implies
Removed the kotlin block from the bottom of that same Gradle file
Synced my Gradle project
Update Kotlin and Gradle (I was asked by Android Studio, you might not be depending on your versions)
Manually removed problem libraries from code, and Alt+Enter'ed any missing libraries back into existence
If you update Gradle, you may also find it necessary to include the following in your Module: app Gradle file inside the android block:
packagingOptions {
exclude 'META-INF/*'
}
(* might be overkill for some, but the suggestion from this post didn't completely eliminate all of my errors.)
After all that, I was then able to rebuild the SDK which loaded to my phone with zero errors.
I'm trying to build the demo app in Tensorflow Lite:
https://www.tensorflow.org/lite/demo_android
Relevant versions:
Tensorlow Lite: 1.12
Android Studio: 3.2.1
Android Sdk: android-28
When I try to make the project included at tensorflow/lite/java/demo I get a build error:
Could not find method jackOptions() for arguments
Presumably this relates to Jack and Jill being deprecated as noted in this related SO article: Could not find method jackOptions() for arguments.
However I'm unclear how it's being used in the Tensorflow demo. My best guess is that using an older version of the SDK might be a temporary solution, so if anyone knows what versions of the various APIs/SDKs will build successfully I would love to know. Or if there's another solution I might apply.
It appears that you can pass this build error by commenting out lines 15, 16, 17 in tensorflow/lite/java/demo/app/build.gradle in the demo app provided in the demo source.
jackOptions {
enabled true
}
This moved me onto another build error at least. I may update this later if there are more relevant details.
I have a project that has started throwing this error when building in Android Studio or Gradle:
com.android.tools.r8.ApiLevelException: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
Now I assume that it's related to use of Java 8 features, perhaps a lambda, but the error message gives no clue as to where the problem lies - it could be my code or it could be a library.
What's the best way to find out where the offending code is? It's a reasonably large app with several modules and quite a few libraries.
In my case i tried to mock something via mockk in an instrumentation test running Api Version 26 or higher, removing the dependency was my only solution as long as following issue is not resolved: https://github.com/mockk/mockk/issues/281
Update: It seems that the issue got resolved and using mockk version 1.10.0 will resolve this issue
One approach would be to set your min api to 26, to avoid the error and build the apk, and then inspect the bytecode of the app (dexdump, baksmali, etc.) to find any usages of the MethodHandle class.
Looking through the error log, it did give a bit more information, specifically nominating one jar file that it failed on:
/Users/.../androidApp/build/intermediates/transforms/desugar/debug/41.jar
On examining that jar file, the classes were all from a library recently added to the project, and the very first class listed was:
META-INF/versions/9/org/h2/util/Bits.class
This turns out to be a Java 9 customised class. Deleting it from the jar file (using zip -d) solved the problem.
Just change the mockk version to 1.10.0, this will resolve the
I have same case when used too high version of Mockito library.
The solution was downgrading from 3.8.0 to 3.4.6. and everything started to work properly.
Error occurred for:
org.mockito:mockito-android:3.8.0
but work for:
org.mockito:mockito-android:3.4.6
We need to update the java version to java 8.
For that please click on File -> Project structure -> app (under Module folder) -> Then select the source compatibility and target compatibility to java 8.
After that you might encounter another error with MethodHandle.invoke and MethodHandle.invokeExact, if you get this error then set the minSdkVersion to 26 or higher