Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Kotlin ExperimentalUnsignedTypes project wide (AndroidStudio)

I'm trying to use the @ExperimentalUnsignedTypes in my AndroidStudio project. It seems I have to put that just about everywhere, so I'd rather set it once project wide.

The documentation says

Usages of such API will be reported as warnings unless an explicit opt-in with the UseExperimental annotation, e.g. @UseExperimental(ExperimentalUnsignedTypes::class), or with the -Xuse-experimental=kotlin.ExperimentalUnsignedTypes compiler option is given.

Dutifully, I have adjusted my Preferences>>Other Settings>>Kotlin Compiler:

enter image description here

But I still get (lots of) warnings after a clean/make. It was suggested that I also add -XXLanguage:+InlineClasses to the same line. But the result is the same. Then I noticed at the top of same preferences pane it says:

enter image description here

Is this my problem? And if so, where can I adjust my app settings so that these compiler settings are effective?

like image 666
Travis Griggs Avatar asked Oct 30 '19 03:10

Travis Griggs


People also ask

How to use Kotlin code in Java project?

To convert Java code to Kotlin, open the Java file in Android Studio, and select Code > Convert Java File to Kotlin File. Alternatively, create a new Kotlin file (File > New > Kotlin File/Class), and then paste your Java code into that file.

How to use Kotlin class in Java Android Studio?

If we want to call the Kotlin code from Java class both present inside the different packages, this requires to import the package name with Kotlin file name inside Java class and calling the Kotlin code from Java class. Another way is to give full path as packageName. KotlinFileKt. methodName().

How do I use OptIn Kotlin?

Allows to use the API denoted by the given markers in the annotated file, declaration, or expression. If a declaration is annotated with OptIn, its usages are not required to opt in to that API. This class requires opt-in itself and can only be used with the compiler argument -opt-in=kotlin.

How to build Android application using Kotlin instead of Java?

As we know Kotlin plugin is bundled with Android Studio above version 3.0, we can build android application using Kotlin language instead of Java. Below are the steps to create a new project in Kotlin programming Language. Step 1: In Welcome to Android Studio screen, select Start a new Android Studio Project.

How to implement retrofit with Kotlin?

Step 1: Creating a new project with Empty activity. Step 2: Setting up the Retrofit HTTP Library and Manifest. Step 3: Implementation of Retrofit with Kotlin. Step 1 - Creating a new project with Kotlin: Open Android Studio and select "Create new project". Name the project as per your wish and tick the "Kotlin Support" checkbox.

Is it possible to use optin instead of experimental in Kotlin?

This is an issue with the Experimental Tag in Kotlin, it is possible to have the OptIn annotation accessible, and then to use that instead of Experimental, as the OptIn does not propagate from the base usage, but this only works if you don't have to use the ExperimentalTime all over the module. Specifically the top block of this link: Opt-In

How to add UML file to Android Studio project?

Well, this method is similar to reverse card, you create a UML first and then import it simply to Android Studio and add it to your project Open the Visual Paradigm program. Make a whole new project.


1 Answers

Even with the spelling correction fixed, it still did not compile correctly. I suspect the "...override project settings..." indeed was problematic. However, placing the following in my (project) gradle file did work:

allprojects {
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            freeCompilerArgs += [
                    "-Xuse-experimental=kotlin.ExperimentalUnsignedTypes",
                    "-XXLanguage:+InlineClasses"
            ]
        }
    }
}
like image 160
Travis Griggs Avatar answered Oct 11 '22 07:10

Travis Griggs