I am trying to use the androidx.compose.ui.window.MenuBar from Jetbrain Tutorial but the problem is that when I try to use it in my project it does not show up.
Here is the problem:
It only offers me to import from those 2 locations but when I use the import it does not complain or resolve the error.
build.gradle.kts
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.0"
}
group = "me.whate"
version = "1.0"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "11"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Test"
packageVersion = "1.0.0"
}
}
}
I have tried to invalidate caches, etc but no success so far.
Anybody has any suggestion?
You have to modify it like this:
#OptIn(ExperimentalComposeUiApi::class)
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
var text by remember { mutableStateOf("Hello, World!") }
DesktopMaterialTheme {
MenuBar {
// your menubar code here
}
Button(onClick = {
text = "Hello, Desktop!"
}) {
Text(text)
}
}
}
}
and completely remove the App() function
Prefix MenuBar with FrameWindowScope, e.g. FrameWindowScope.MenuBar
Related
I have issue in build.gradle first i got DSO error tht i solved by using custom plugin and added into app.json but after that I got another error like No static method createEGl14 so I updated the minSdkVersion = 24 but that lead me to the again DSO problem.
//build.gradle
buildscript {
ext {
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '31.0.0'
// minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '24')
minSdkVersion = 24
compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '31')
targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '31')
if (findProperty('android.kotlinVersion')) {
kotlinVersion = findProperty('android.kotlinVersion')
}
frescoVersion = findProperty('expo.frescoVersion') ?: '2.5.0'
if (System.properties['os.arch'] == 'aarch64') {
// For M1 Users we need to use the NDK 24 which added support for aarch64
ndkVersion = '24.0.8215888'
} else {
// Otherwise we default to the side-by-side NDK version from AGP.
ndkVersion = '21.4.7075529'
}
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath('com.android.tools.build:gradle:7.2.1')
classpath('com.facebook.react:react-native-gradle-plugin')
classpath('de.undercouch:gradle-download-task:5.0.1')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
def REACT_NATIVE_VERSION = new File(['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android'))
}
maven {
// Android JSC is installed from npm
url(new File(['node', '--print', "require.resolve('jsc-android/package.json')"].execute(null, rootDir).text.trim(), '../dist'))
}
google()
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup 'com.facebook.react'
}
}
maven { url 'https://www.jitpack.io' }
}
}
//custome plugin to solve DSO issue.
const {
createRunOncePlugin,
withAppBuildGradle,
} = require("#expo/config-plugins");
const withAppBuildGradleModified = (config) => {
return withAppBuildGradle(config, async (file) => {
const modResults = file.modResults;
modResults.contents =
modResults.contents +
"\nandroid.packagingOptions.jniLibs.useLegacyPackaging = true\n";
return file;
});
};
module.exports = createRunOncePlugin(
withAppBuildGradleModified,
"withAppBuildGradleModified",
"1.0.0"
);
//app.json
{
"expo": {
"name": "videocall_webrtc",
"slug": "videocall_webrtc",
"version": "1.0.0",
"assetBundlePatterns": ["**/*"],
"plugins": ["./plugin.js", "#config-plugins/react-native-webrtc"]
}
}
Could you please help me how to resolve this issue. I am using JDK 11 and not using EAS build it is an Bare expo project. Could you please share any example or anything that could help me. Thank you in advance.
I just started a desktop project with Intellij, built with the default generated code, ran it on Linux, and it worked. Then I added a counter variable for the button text (shown as follows), it also ran as before. But when I click on the button, the change of text on reaction to the click takes as long as 10 seconds. Wonder what can be wrong.
I am running Xubuntu 22.04.
#Composable
#Preview
fun App() {
var text by remember { mutableStateOf("Hello, World!") }
var ic by remember { mutableStateOf(0) }
MaterialTheme {
Button(onClick = {
ic++
text = "Hello, Desktop! $ic"
}) {
Text(text)
}
}
}
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}
My build.gradle:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.1"
}
group = "me.xxxx"
version = "1.0"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Test"
packageVersion = "1.0.0"
}
}
}
Well, it turns out a VirtualBox setting issue. I run Xubuntu on VirtualBox hosted by MacBook Pro. I need to set graphics controller to VMSVGA on VirtualBox. So now it's responsive.
I just started using Micronaut, but I can't get a simple endpoint to work. I get this response for http://localhost:8901/game_compositions/
{
"message": "Page Not Found",
"_links": {
"self": {
"href": "/game_compositions/",
"templated": false
}
}
}
I have seen a few other questions here about the same response but none of them helped me. I have annotation processor activated for my build and I do not return null.
I assume I have some simple stupid mistake, but I can't find it. According to the sample projects I seem to have all I need.
This is my project:
Controller:
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Produces
#Controller("/game_compositions")
class CompositionsController {
#Produces(MediaType.APPLICATION_JSON)
#Get(uri = "/")
fun getCompositions(): Iterable<String> {
return listOf("something")
}
}
Build.gradle (mostly autogenerated from the https://micronaut.io/launch/ site, so there might be some unnecessary stuff there for a simple service. Feel free to point it out)
plugins {
id("io.micronaut.application") version "1.2.0"
kotlin("jvm") version "1.4.10"
kotlin("kapt") version "1.4.10"
kotlin("plugin.allopen") version "1.4.10"
}
version = "0.1"
group = "com.example.backend"
val kotlinVersion=project.properties.get("kotlinVersion")
repositories {
mavenCentral()
jcenter()
}
micronaut {
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("com.example.backend.*")
}
}
dependencies {
implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut.sql:micronaut-jdbc-hikari")
implementation("io.micronaut.sql:micronaut-hibernate-jpa")
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
}
application {
mainClass.set("com.example.backend.ApplicationKt")
}
java {
sourceCompatibility = JavaVersion.toVersion("14")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "14"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "14"
}
}
}
Application.yml (the database connection is so far unused untested)
micronaut:
application:
name: Backend
server:
port: 8901
datasources:
default:
url: jdbc:mysql://localhost:3306/db
username: root
password: root
driver-class-name: org.mariadb.jdbc.Driver
jpa:
default:
properties:
hibernate:
hbm2ddl:
auto: none
show_sql: true
Thanks to Jeff Scott Brown in the comments I have been able to determine that the order of the plugins is the problem. I was not aware that the order mattered in gradle. Apparently Micronaut requires the kapt plugin to be added first. Anyone with more insight in to this is welcome to post a better answer, for me it worked to change the start of my gradle file to this:
plugins {
kotlin("jvm") version "1.4.10"
kotlin("kapt") version "1.4.10"
id("io.micronaut.application") version "1.2.0"
kotlin("plugin.allopen") version "1.4.10"
}
Edit: An important note if anyone attempts to use my gradle file. It turns out kapt does not support java 14 and that caused some very hard to track down trouble for me. This is my current working gradle file:
plugins {
kotlin("jvm") version "1.4.10"
kotlin("kapt") version "1.4.10"
kotlin("plugin.allopen") version "1.4.10"
kotlin("plugin.jpa") version "1.4.10"
id("io.micronaut.application") version "1.2.0"
}
version = "0.1"
group = "com.example.backend"
val kotlinVersion: String by project
repositories {
mavenCentral()
jcenter()
}
micronaut {
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("com.example.backend.*")
}
}
dependencies {
annotationProcessor("io.micronaut.data:micronaut-data-processor")
implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut.sql:micronaut-jdbc-hikari")
implementation("io.micronaut.sql:micronaut-hibernate-jpa")
implementation("io.micronaut.data:micronaut-data-hibernate-jpa")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
}
application {
mainClass.set("com.example.backend.ApplicationKt")
}
java {
sourceCompatibility = JavaVersion.toVersion("11")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
}
I downloaded from micronaut.lanch a simple grpc project and I can build it until I add Kotlin gRPC plugin.
Beyond the changes in build.gradle.kts, there is nothing else than the original scafolded project.
I edited in build.gradle.kts.
Firstly, in order to match IntelliJ Kotlin version
plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.21"
id("org.jetbrains.kotlin.kapt") version "1.4.21"
id("org.jetbrains.kotlin.plugin.allopen") version "1.4.21"
Seconddly, added folder for kotlin grpc proto autogenerated files
sourceSets {
main {
java {
...
srcDirs ("build/generated/source/proto/main/grpckt")
And finally
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.14.0"
}
plugins {
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:1.33.1"
}
id("grpckt")
{ artifact = "io.grpc:protoc-gen-grpc-kotlin:0.1.2" }
}
generateProtoTasks {
ofSourceSet("main").forEach {
it.plugins {
// Apply the "grpc" plugin whose spec is defined above, without options.
id("grpc")
id("grpckt")
}
}
}
}
The result while building either from INtelliJ or straigh from command line is
C:\_d\toLearn\kafka-proto\build\tmp\kapt3\stubs\main\com\test\KafkaProtoServiceGrpcKt.java:35: error: incompatible types: NonExistentClass cannot be converted to Annotation
#error.NonExistentClass()
*** edited
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
}
dependsOn ="generateProto" //how add this ?????
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
}
*** EDIT 2
I tried another project. I started from scratch and I am stuck on same issue again.
Here is the build.gradle
plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.10"
id("org.jetbrains.kotlin.kapt") version "1.4.10"
id("org.jetbrains.kotlin.plugin.allopen") version "1.4.10"
id("com.github.johnrengelman.shadow") version "6.1.0"
id("io.micronaut.application") version "1.2.0"
id("com.google.protobuf") version "0.8.13"
}
version = "0.1"
group = "com.tolearn"
repositories {
mavenCentral()
jcenter()
}
micronaut {
testRuntime("junit5")
processing {
incremental(true)
annotations("com.tolearn.*")
}
}
//https://stackoverflow.com/a/55646891/4148175
//kapt {
// correctErrorTypes true
//}
dependencies {
//implementation("io.grpc:protoc-gen-grpc-kotlin:1.0.0")
implementation("io.micronaut:micronaut-validation")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut.grpc:micronaut-grpc-runtime")
implementation("javax.annotation:javax.annotation-api")
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-tracing")
runtimeOnly("io.jaegertracing:jaeger-thrift")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
}
application {
mainClass.set("com.tolearn.ApplicationKt")
}
java {
sourceCompatibility = JavaVersion.toVersion("11")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
}
dependsOn ':generateProto'
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
}
sourceSets {
main {
java {
srcDirs("build/generated/source/proto/main/grpc")
srcDirs 'build/generated/source/proto/main/grpckt'
srcDirs("build/generated/source/proto/main/java")
}
}
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:3.14.0" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:1.33.1" }
grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:1.0.0:jdk7#jar"}
}
generateProtoTasks {
all()*.plugins {
grpc {}
grpckt {}
}
}
}
The issue is raised on autogenerated stub
Here is the full code github
I fixed the issue by adding api("io.grpc:grpc-kotlin-stub:1.0.0") Thanks to https://github.com/grpc/grpc-kotlin/issues/220 help.
So my build.gradle is now:
plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.10"
id("org.jetbrains.kotlin.kapt") version "1.4.10"
id("org.jetbrains.kotlin.plugin.allopen") version "1.4.10"
id("com.github.johnrengelman.shadow") version "6.1.0"
id("io.micronaut.application") version "1.2.0"
id("com.google.protobuf") version "0.8.13"
}
version = "0.1"
group = "com.tolearn"
repositories {
mavenCentral()
jcenter()
}
micronaut {
testRuntime("junit5")
processing {
incremental(true)
annotations("com.tolearn.*")
}
}
//https://stackoverflow.com/a/55646891/4148175
//https://kotlinlang.org/docs/reference/kapt.html
//kapt {
// correctErrorTypes true
// useBuildCache = false
//}
dependencies {
implementation("io.grpc:protoc-gen-grpc-kotlin:1.0.0")
api("io.grpc:grpc-kotlin-stub:1.0.0")
implementation("io.micronaut:micronaut-validation")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut.grpc:micronaut-grpc-runtime")
implementation("javax.annotation:javax.annotation-api")
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-tracing")
runtimeOnly("io.jaegertracing:jaeger-thrift")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
}
application {
mainClass.set("com.tolearn.ApplicationKt")
}
java {
sourceCompatibility = JavaVersion.toVersion("11")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
}
dependsOn ':generateProto'
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
}
sourceSets {
main {
java {
srcDirs("build/generated/source/proto/main/grpc")
srcDirs 'build/generated/source/proto/main/grpckt'
srcDirs("build/generated/source/proto/main/java")
}
}
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:3.14.0" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:1.33.1" }
grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:1.0.0:jdk7#jar"}
}
generateProtoTasks {
all()*.plugins {
grpc {}
grpckt {}
}
}
}
I'm following this guide but "TheApp" portion is highlighted red and I get a blank webpage as output. Do I need to import some library for this to get recognized?
Also if I'm not passing any data into the template can I leave the 'model' as a blank string?
My kotlin code:
import io.ktor.server.netty.*
import io.ktor.routing.*
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.server.engine.*
import freemarker.cache.*
import io.ktor.freemarker.*
import io.ktor.freemarker.FreeMarkerContent
fun main(args: Array<String>) {
embeddedServer(Netty, 3000) {
install(FreeMarker) {
templateLoader = ClassTemplateLoader(TheApp::class.java.classLoader, "templates")
}
routing {
get("/") {
call.respond(FreeMarkerContent("templ.ftl", "", "e"))
}
}
}.start(wait = true) }
gradle portion:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}
group 'rest-group'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
ext.ktor_version = '1.1.3'
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "io.ktor:ktor:$ktor_version"
compile "io.ktor:ktor-gson:$ktor_version"
compile "io.ktor:ktor-freemarker:$ktor_version"
compile "io.ktor:ktor-html-builder:$ktor_version"
compile "io.ktor:ktor-server-netty:$ktor_version"
compile "io.ktor:ktor-auth:$ktor_version"
compile "io.ktor:ktor:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.3"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
'TheApp' needs to be replaced with 'this'. 'this' picks up the instance of the application being run for ktor.
'model' needs to be a mapOf reference type even if the values aren't being used.