Programming Android With Kotlin

1 view
Skip to first unread message

Malene Mederios

unread,
Aug 4, 2024, 8:50:56 PM8/4/24
to sanosara
Inmy current Rust/wasm32 app, I create a full sized canvas, open a WebGL context and draw everything in WebGL. Text is rendered via textures. "Buttons" consists of GL Lines, Quads, and Textures. Hover effects is by manually toggling button colors. Drag/Drag involves manually updating locations of quads.

It's a very barebones interface that is exposed by the NDK, meaning you need to do everything from loading OpenGL ES to writing (or using a preexisting) gui/drawing library. I currently use a locally modified piston clone.


In wasm32, I use set panic hook to capture panics. Then I can print out a file name / line number before it dies. On Android/NDK, on crashes, even if you don't get full stack trace, can you at least get a file name / line number before program dies?


I don't want to sound entitled here -- Is there something I can git clone? This sounds like the type of issue where copy/paste is much easier than spending a weekend trying to figure out all the cargo / compiler / linkier flags.


Be careful, since lines/points aren't stable throughout OpenGLES implementations, and I found that the one I was personally using (On a Pixel 2 for reference) had weird primitive count bugs, so I ended up having to use a quad.


Let me see if I can create essentially the project shown in the thread I mentioned above. I'll also include my local opengl_graphics clone which has been modified to allow more flexible shader interop and to make it compatible with newer OpenGL ES versions in the build script and some other places since the opengles_graphics crate is heavily out of date and my own optimisticpeach_opengles_graphics is already old and I was very inexperienced with OpenGL at the time.


I'm a big fan of Kotlin/IntelliJ (so much so it pulled me away from Emacs). However, for graphics / real time work, I really want my RAII, memory layout, and ability to control when allocations happen.


Thanks the concrete "stack traces". They look good enough. For rust code, all I need is file name + line number; and for vertex/frag shaders, all I need is just filename/line_number of compile error (during runtime of rust code).


It's not that bad; I just timed the app I pushed and it took about 23s, but that can be optimized if you don't make opengl_graphics rebuild the opengl api every time by changing line 10 of build.rs to this:


I chose ../gl.rs because the output directory I'm supposed to output to (In target) is inaccessible by IntelliJ, and putting it in ./src causes it to rebuild each time. Otherwise, there's little to be done; cargo apk rebuilds the glue every time unfortunately, and building an APK is just slow.


Full time android developer and hobbyist rust developer here. For android development I am fully Android Studio and Kotlin. I haven't done much work trying to bridge the two. My current understanding is you can access parts of the android framework though the NDK but it will be limited what you can do and the interfaces aren't terribly fun to work with when you are used to the high level abstractions. I don't have a lot of experience with it beyond just looking into it but I'm always happy to answer android / kotlin /java questions if you have any.


my android studio started working with kotlin and not java after the last update. I have a university project that I need to deliver soon and we only learned coding with java, can anyone please help me find a way to return it to java thanks a lot


side personal notes:

This behavior is not typical to Google and is very surprising and aggressive.It becomes dangerous to upgrade versions these days.People love Java and are use to it.It is great that Kotlin support was added but yet Java is powerful amazing programming language that will stay forever.I use Java also for server side and for desktop applications so it is convenient to use same programming language for multiple platforms.Android Studio doesn't even explain the change clearly.


If I understand your problem correctly, when you create new project you have to uncheck "Include Kotlin support" checkbox at the bottom of "Create new project" window.And remember that you can create java classes in Kotlin project.


Kotlin (/ˈkɒtlɪn/)[2] is a cross-platform, statically typed, general-purpose high-level programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library,but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript (e.g., for frontend web applications using React)[3] or native code via LLVM (e.g., for native iOS apps sharing business logic with Android apps).[4] Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.[5]


On 7 May 2019, Google announced that the Kotlin programming language was now its preferred language for Android app developers.[6] Since the release of Android Studio 3.0 in October 2017, Kotlin has been included as an alternative to the standard Java compiler. The Android Kotlin compiler produces Java 8 bytecode by default (which runs in any later JVM), but lets the programmer choose to target Java 9 up to 20, for optimization,[7] or allows for more features; has bidirectional record class interoperability support for JVM, introduced in Java 16, considered stable as of Kotlin 1.5.


Kotlin has support for the web with Kotlin/JS, either through a classic interpreter-based backend which has been declared stable since version 1.3, or an intermediate representation-based backend which has been declared stable since version 1.8. Kotlin/Native (for e.g. Apple silicon support) is considered beta since version 1.3.[8][9]


The name is derived from Kotlin Island, a Russian island in the Gulf of Finland, near St. Petersburg. Andrey Breslav, Kotlin's former lead designer, mentioned that the team decided to name it after an island, just like the programming language Java was named after the Indonesian island of Java[10] (though the language's name is said to have been inspired by "java" the American slang term for coffee,[11] which itself is derived from the island name).[12]


In July 2011, JetBrains unveiled Project Kotlin, a new language for the JVM, which had been under development for a year.[13] JetBrains lead Dmitry Jemerov said that most languages did not have the features they were looking for, with the exception of Scala. However, he cited the slow compilation time of Scala as a deficiency.[13] One of the stated goals of Kotlin is to compile as quickly as Java. In February 2012, JetBrains open sourced the project under the Apache 2 license.[14]


Kotlin 1.0 was released on February 15, 2016.[17] This is considered to be the first officially stable release and JetBrains has committed to long-term backwards compatibility starting with this version.


Kotlin 1.2 was released on November 28, 2017.[19] Sharing code between JVM and JavaScript platforms feature was newly added to this release (multiplatform programming is by now a beta feature[20] upgraded from "experimental"). A full-stack demo has been made with the new Kotlin/JS Gradle Plugin.[21][22]


Development lead Andrey Breslav has said that Kotlin is designed to be an industrial-strength object-oriented language, and a "better language" than Java, but still be fully interoperable with Java code, allowing companies to make a gradual migration from Java to Kotlin.[29]


Borrowing from Scala, Kotlin variable declarations and parameter lists have the data type come after the variable name (and with a colon separator), similar to Ada, BASIC, Pascal, TypeScript and Rust. This, according to an article from Roman Elizarov, current project lead, results in alignment of variable names and is more pleasing to eyes, especially when there are a few variable declarations in succession, and one or more of the types is too complex for type inference, or needs to be declared explicitly for human readers to understand.[31][32]


Borrowing from Scala, class members are public by default, and classes themselves are final by default, meaning that creating a derived class is disabled unless the base class is declared with the open keyword.


In addition to the classes and member functions (which are equivalent to methods) of object-oriented programming, Kotlin also supports procedural programming with the use of functions.[34]Kotlin functions and constructors support default arguments, variable-length argument lists, named arguments, and overloading by unique signature. Class member functions are virtual, i.e. dispatched based on the runtime type of the object they are called on.


Kotlin 1.3 added support for contracts,[35] which are stable for the standard library declarations, but still experimental for user-defined declarations. Contracts are inspired by Eiffel's design by contract[36] programming paradigm.


Following ScalaJS, Kotlin code may be transpiled to JavaScript, allowing for interoperability between code written in the two languages. This can be used either to write full web applications in Kotlin, or to share code between a Kotlin backend and a JavaScript frontend.[37]


Kotlin relaxes Java's restriction of allowing static methods and variables to exist only within a class body. Static objects and functions can be defined at the top level of the package without needing a redundant class level. For compatibility with Java, Kotlin provides a JvmName annotation which specifies a class name used when the package is viewed from a Java project. For example, @file:JvmName("JavaClassName").

3a8082e126
Reply all
Reply to author
Forward
0 new messages