Java Question Wrap lib from pure Kotlin

Pendrush

Well-Known Member
Licensed User
Longtime User
I'm trying to wrap simple library from pure Kotlin including wrapper. I have succeeded, but I have some question.

This is Kotlin code:
Java:
package com.example.wrapper

import anywheresoftware.b4a.BA
import anywheresoftware.b4a.BA.ShortName
import anywheresoftware.b4a.BA.Events
import anywheresoftware.b4a.BA.DependsOn
import anywheresoftware.b4a.BA.Version
import com.example.mylib.TestLib

@ShortName("LibTest")
@BA.Permissions(values=["android.permission.ACCESS_FINE_LOCATION"])
@Events(values = ["TestEvent"])
@DependsOn(values = ["mylib-release.aar", "kotlin-stdlib-1.3.71", "annotations-13.0"])
@Version(1.0f)

public open class Wrapper {

    val a = TestLib()
    fun Initialize() {
    }

    fun HelloWorld(): String {
        return a.stringTest()
    }
}


This is Java code returned from bytecode (decompile) from Tools->Kotlin->Show Kotlin Bytecode, then click on Decompile button:
Java:
package com.example.wrapper;

import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import com.example.mylib.TestLib;
import kotlin.Metadata;
import org.jetbrains.annotations.NotNull;

@ShortName("LibTest")
@Version(1.0F)
@Metadata(
   mv = {1, 1, 16},
   bv = {1, 0, 3},
   k = 1,
   d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u0002\n\u0000\b\u0017\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0006\u0010\u0007\u001a\u00020\bJ\u0006\u0010\t\u001a\u00020\nR\u0011\u0010\u0003\u001a\u00020\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0005\u0010\u0006¨\u0006\u000b"},
   d2 = {"Lcom/example/wrapper/Wrapper;", "", "()V", "a", "Lcom/example/mylib/TestLib;", "getA", "()Lcom/example/mylib/TestLib;", "HelloWorld", "", "Initialize", "", "wrapper_release"}
)
public class Wrapper {
   @NotNull
   private final TestLib a = new TestLib();

   @NotNull
   public final TestLib getA() {
      return this.a;
   }

   public final void Initialize() {
   }

   @NotNull
   public final String HelloWorld() {
      return this.a.stringTest();
   }
}


If you look closely this part is missing in decompiled Java code:
Java:
import anywheresoftware.b4a.BA.Events
import anywheresoftware.b4a.BA.DependsOn

@BA.Permissions(values=["android.permission.ACCESS_FINE_LOCATION"])
@Events(values = ["TestEvent"])
@DependsOn(values = ["mylib-release.aar", "kotlin-stdlib-1.3.71", "annotations-13.0"])


I can add this part manually, but question is why some imports and some annotations is missing?

EDIT:
Annotations and imports also missing in bytecode, here is bytecode:
// ================com/example/wrapper/Wrapper.class =================
// class version 50.0 (50)
// access flags 0x21
public class com/example/wrapper/Wrapper {

@Lanywheresoftware/b4a/BA$ShortName;(value="LibTest")
@Lanywheresoftware/b4a/BA$Version;(value=1.0F)

// access flags 0x12
private final Lcom/example/mylib/TestLib; a

// access flags 0x11
public final Initialize()V
L0
LINENUMBER 24 L0
RETURN
L1
LOCALVARIABLE this Lcom/example/wrapper/Wrapper; L0 L1 0
MAXSTACK = 0
MAXLOCALS = 1

// access flags 0x11
public final HelloWorld()Ljava/lang/String;
@Lorg/jetbrains/annotations/NotNull;() // invisible
L0
LINENUMBER 28 L0
ALOAD 0
GETFIELD com/example/wrapper/Wrapper.a : Lcom/example/mylib/TestLib;
INVOKEVIRTUAL com/example/mylib/TestLib.stringTest ()Ljava/lang/String;
ARETURN
L1
LOCALVARIABLE this Lcom/example/wrapper/Wrapper; L0 L1 0
MAXSTACK = 1
MAXLOCALS = 1

// access flags 0x1
public <init>()V
L0
LINENUMBER 18 L0
ALOAD 0
INVOKESPECIAL java/lang/Object.<init> ()V
L1
LINENUMBER 20 L1
ALOAD 0
NEW com/example/mylib/TestLib
DUP
INVOKESPECIAL com/example/mylib/TestLib.<init> ()V
PUTFIELD com/example/wrapper/Wrapper.a : Lcom/example/mylib/TestLib;
RETURN
L2
LOCALVARIABLE this Lcom/example/wrapper/Wrapper; L0 L2 0
MAXSTACK = 3
MAXLOCALS = 1

@Lkotlin/Metadata;(mv={1, 1, 16}, bv={1, 0, 3}, k=1, d1={"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0008\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u0002\n\u0000\u0008\u0017\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002J\u0006\u0010\u0005\u001a\u00020\u0006J\u0006\u0010\u0007\u001a\u00020\u0008R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004\u00a2\u0006\u0002\n\u0000\u00a8\u0006\u0009"}, d2={"Lcom/example/wrapper/Wrapper;", "", "()V", "a", "Lcom/example/mylib/TestLib;", "HelloWorld", "", "Initialize", "", "wrapper_release"})
// access flags 0x2609
public static abstract INNERCLASS anywheresoftware/b4a/BA$ShortName anywheresoftware/b4a/BA ShortName
// access flags 0x2609
public static abstract INNERCLASS anywheresoftware/b4a/BA$Version anywheresoftware/b4a/BA Version
// access flags 0x2609
public static abstract INNERCLASS anywheresoftware/b4a/BA$Author anywheresoftware/b4a/BA Author
// compiled from: Wrapper.kt
}

// ================META-INF/wrapper_release.kotlin_module =================


PS.
My test lib work flawlessly in B4a, written and wrapped in pure Kotlin for B4a.
 
Last edited:
Top