From c71ddeba6235ac0d4149c46f8dbefd010a8a0c1c Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Tue, 15 Oct 2024 01:52:50 +0200 Subject: [PATCH] [jnigen] Fix generating packages in Android (#1656) --- pkgs/jnigen/CHANGELOG.md | 2 + pkgs/jnigen/example/in_app_java/jnigen.yaml | 2 +- .../in_app_java/lib/android_utils.dart | 243 ++++++++++++++++++ .../apisummarizer/util/ClassFinder.java | 6 +- 4 files changed, 248 insertions(+), 5 deletions(-) diff --git a/pkgs/jnigen/CHANGELOG.md b/pkgs/jnigen/CHANGELOG.md index a8d51a74e..1aa41d301 100644 --- a/pkgs/jnigen/CHANGELOG.md +++ b/pkgs/jnigen/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.12.2-wip - Now excludes invalid identifiers by default. +- Fixed a bug where if multiple jars have classes within the same package, only + one of them gets generated. ## 0.12.1 diff --git a/pkgs/jnigen/example/in_app_java/jnigen.yaml b/pkgs/jnigen/example/in_app_java/jnigen.yaml index 3fa8640b9..bdcdbf3cd 100644 --- a/pkgs/jnigen/example/in_app_java/jnigen.yaml +++ b/pkgs/jnigen/example/in_app_java/jnigen.yaml @@ -9,7 +9,7 @@ output: source_path: - 'android/app/src/main/java' classes: - - 'com.example.in_app_java.AndroidUtils' # from source_path + - 'com.example.in_app_java' # Generate the entire package - 'androidx.emoji2.text.EmojiCompat' # From gradle's compile classpath - 'androidx.emoji2.text.DefaultEmojiCompatConfig' # From gradle's compile classpath - 'android.os.Build' # from gradle's compile classpath diff --git a/pkgs/jnigen/example/in_app_java/lib/android_utils.dart b/pkgs/jnigen/example/in_app_java/lib/android_utils.dart index 2b7a33e06..b074990c6 100644 --- a/pkgs/jnigen/example/in_app_java/lib/android_utils.dart +++ b/pkgs/jnigen/example/in_app_java/lib/android_utils.dart @@ -34,6 +34,249 @@ import 'dart:core' as _$core; import 'package:jni/_internal.dart' as _$jni; import 'package:jni/jni.dart' as _$jni; +/// from: `com.example.in_app_java.R$drawable` +class R_drawable extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType $type; + + @_$jni.internal + R_drawable.fromReference( + _$jni.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static final _class = + _$jni.JClass.forName(r'com/example/in_app_java/R$drawable'); + + /// The type which includes information such as the signature of this class. + static const type = $R_drawable$Type(); + static final _id_launch_background = _class.staticFieldId( + r'launch_background', + r'I', + ); + + /// from: `static public int launch_background` + static int get launch_background => + _id_launch_background.get(_class, const _$jni.jintType()); + + /// from: `static public int launch_background` + static set launch_background(int value) => + _id_launch_background.set(_class, const _$jni.jintType(), value); +} + +final class $R_drawable$Type extends _$jni.JObjType { + @_$jni.internal + const $R_drawable$Type(); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/example/in_app_java/R$drawable;'; + + @_$jni.internal + @_$core.override + R_drawable fromReference(_$jni.JReference reference) => + R_drawable.fromReference(reference); + + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => ($R_drawable$Type).hashCode; + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($R_drawable$Type) && other is $R_drawable$Type; + } +} + +/// from: `com.example.in_app_java.R$mipmap` +class R_mipmap extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType $type; + + @_$jni.internal + R_mipmap.fromReference( + _$jni.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static final _class = + _$jni.JClass.forName(r'com/example/in_app_java/R$mipmap'); + + /// The type which includes information such as the signature of this class. + static const type = $R_mipmap$Type(); + static final _id_ic_launcher = _class.staticFieldId( + r'ic_launcher', + r'I', + ); + + /// from: `static public int ic_launcher` + static int get ic_launcher => + _id_ic_launcher.get(_class, const _$jni.jintType()); + + /// from: `static public int ic_launcher` + static set ic_launcher(int value) => + _id_ic_launcher.set(_class, const _$jni.jintType(), value); +} + +final class $R_mipmap$Type extends _$jni.JObjType { + @_$jni.internal + const $R_mipmap$Type(); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/example/in_app_java/R$mipmap;'; + + @_$jni.internal + @_$core.override + R_mipmap fromReference(_$jni.JReference reference) => + R_mipmap.fromReference(reference); + + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => ($R_mipmap$Type).hashCode; + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($R_mipmap$Type) && other is $R_mipmap$Type; + } +} + +/// from: `com.example.in_app_java.R$style` +class R_style extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType $type; + + @_$jni.internal + R_style.fromReference( + _$jni.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static final _class = + _$jni.JClass.forName(r'com/example/in_app_java/R$style'); + + /// The type which includes information such as the signature of this class. + static const type = $R_style$Type(); + static final _id_LaunchTheme = _class.staticFieldId( + r'LaunchTheme', + r'I', + ); + + /// from: `static public int LaunchTheme` + static int get LaunchTheme => + _id_LaunchTheme.get(_class, const _$jni.jintType()); + + /// from: `static public int LaunchTheme` + static set LaunchTheme(int value) => + _id_LaunchTheme.set(_class, const _$jni.jintType(), value); + + static final _id_NormalTheme = _class.staticFieldId( + r'NormalTheme', + r'I', + ); + + /// from: `static public int NormalTheme` + static int get NormalTheme => + _id_NormalTheme.get(_class, const _$jni.jintType()); + + /// from: `static public int NormalTheme` + static set NormalTheme(int value) => + _id_NormalTheme.set(_class, const _$jni.jintType(), value); +} + +final class $R_style$Type extends _$jni.JObjType { + @_$jni.internal + const $R_style$Type(); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/example/in_app_java/R$style;'; + + @_$jni.internal + @_$core.override + R_style fromReference(_$jni.JReference reference) => + R_style.fromReference(reference); + + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => ($R_style$Type).hashCode; + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($R_style$Type) && other is $R_style$Type; + } +} + +/// from: `com.example.in_app_java.R` +class R extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType $type; + + @_$jni.internal + R.fromReference( + _$jni.JReference reference, + ) : $type = type, + super.fromReference(reference); + + static final _class = _$jni.JClass.forName(r'com/example/in_app_java/R'); + + /// The type which includes information such as the signature of this class. + static const type = $R$Type(); +} + +final class $R$Type extends _$jni.JObjType { + @_$jni.internal + const $R$Type(); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/example/in_app_java/R;'; + + @_$jni.internal + @_$core.override + R fromReference(_$jni.JReference reference) => R.fromReference(reference); + + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => ($R$Type).hashCode; + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($R$Type) && other is $R$Type; + } +} + /// from: `androidx.emoji2.text.EmojiCompat$CodepointSequenceMatchResult` class EmojiCompat_CodepointSequenceMatchResult extends _$jni.JObject { @_$jni.internal diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/util/ClassFinder.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/util/ClassFinder.java index 89d7f307a..e959ce9e0 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/util/ClassFinder.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/util/ClassFinder.java @@ -119,13 +119,11 @@ public static boolean findFilesInJar( jar.stream().map(JarEntry::getName).collect(Collectors.toCollection(TreeSet::new)); boolean foundClassesInThisJar = false; for (var fqn : classes.keySet()) { - if (classes.get(fqn) != null) { // already found - continue; - } var resultPaths = findClassAndChildren(entryNames, fqn, jarSeparator, suffix); if (resultPaths.isPresent()) { var jarEntries = resultPaths.get().stream().map(jar::getEntry).collect(Collectors.toList()); - classes.put(fqn, mapper.apply(jar, jarEntries)); + classes.putIfAbsent(fqn, new ArrayList<>()); + classes.get(fqn).addAll(mapper.apply(jar, jarEntries)); foundClassesInThisJar = true; } }