Skip to content

Commit c71ddeb

Browse files
[jnigen] Fix generating packages in Android (#1656)
1 parent 1a832b7 commit c71ddeb

File tree

4 files changed

+248
-5
lines changed

4 files changed

+248
-5
lines changed

pkgs/jnigen/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## 0.12.2-wip
22

33
- Now excludes invalid identifiers by default.
4+
- Fixed a bug where if multiple jars have classes within the same package, only
5+
one of them gets generated.
46

57
## 0.12.1
68

pkgs/jnigen/example/in_app_java/jnigen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ output:
99
source_path:
1010
- 'android/app/src/main/java'
1111
classes:
12-
- 'com.example.in_app_java.AndroidUtils' # from source_path
12+
- 'com.example.in_app_java' # Generate the entire package
1313
- 'androidx.emoji2.text.EmojiCompat' # From gradle's compile classpath
1414
- 'androidx.emoji2.text.DefaultEmojiCompatConfig' # From gradle's compile classpath
1515
- 'android.os.Build' # from gradle's compile classpath

pkgs/jnigen/example/in_app_java/lib/android_utils.dart

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,249 @@ import 'dart:core' as _$core;
3434
import 'package:jni/_internal.dart' as _$jni;
3535
import 'package:jni/jni.dart' as _$jni;
3636

37+
/// from: `com.example.in_app_java.R$drawable`
38+
class R_drawable extends _$jni.JObject {
39+
@_$jni.internal
40+
@_$core.override
41+
final _$jni.JObjType<R_drawable> $type;
42+
43+
@_$jni.internal
44+
R_drawable.fromReference(
45+
_$jni.JReference reference,
46+
) : $type = type,
47+
super.fromReference(reference);
48+
49+
static final _class =
50+
_$jni.JClass.forName(r'com/example/in_app_java/R$drawable');
51+
52+
/// The type which includes information such as the signature of this class.
53+
static const type = $R_drawable$Type();
54+
static final _id_launch_background = _class.staticFieldId(
55+
r'launch_background',
56+
r'I',
57+
);
58+
59+
/// from: `static public int launch_background`
60+
static int get launch_background =>
61+
_id_launch_background.get(_class, const _$jni.jintType());
62+
63+
/// from: `static public int launch_background`
64+
static set launch_background(int value) =>
65+
_id_launch_background.set(_class, const _$jni.jintType(), value);
66+
}
67+
68+
final class $R_drawable$Type extends _$jni.JObjType<R_drawable> {
69+
@_$jni.internal
70+
const $R_drawable$Type();
71+
72+
@_$jni.internal
73+
@_$core.override
74+
String get signature => r'Lcom/example/in_app_java/R$drawable;';
75+
76+
@_$jni.internal
77+
@_$core.override
78+
R_drawable fromReference(_$jni.JReference reference) =>
79+
R_drawable.fromReference(reference);
80+
81+
@_$jni.internal
82+
@_$core.override
83+
_$jni.JObjType get superType => const _$jni.JObjectType();
84+
85+
@_$jni.internal
86+
@_$core.override
87+
final superCount = 1;
88+
89+
@_$core.override
90+
int get hashCode => ($R_drawable$Type).hashCode;
91+
92+
@_$core.override
93+
bool operator ==(Object other) {
94+
return other.runtimeType == ($R_drawable$Type) && other is $R_drawable$Type;
95+
}
96+
}
97+
98+
/// from: `com.example.in_app_java.R$mipmap`
99+
class R_mipmap extends _$jni.JObject {
100+
@_$jni.internal
101+
@_$core.override
102+
final _$jni.JObjType<R_mipmap> $type;
103+
104+
@_$jni.internal
105+
R_mipmap.fromReference(
106+
_$jni.JReference reference,
107+
) : $type = type,
108+
super.fromReference(reference);
109+
110+
static final _class =
111+
_$jni.JClass.forName(r'com/example/in_app_java/R$mipmap');
112+
113+
/// The type which includes information such as the signature of this class.
114+
static const type = $R_mipmap$Type();
115+
static final _id_ic_launcher = _class.staticFieldId(
116+
r'ic_launcher',
117+
r'I',
118+
);
119+
120+
/// from: `static public int ic_launcher`
121+
static int get ic_launcher =>
122+
_id_ic_launcher.get(_class, const _$jni.jintType());
123+
124+
/// from: `static public int ic_launcher`
125+
static set ic_launcher(int value) =>
126+
_id_ic_launcher.set(_class, const _$jni.jintType(), value);
127+
}
128+
129+
final class $R_mipmap$Type extends _$jni.JObjType<R_mipmap> {
130+
@_$jni.internal
131+
const $R_mipmap$Type();
132+
133+
@_$jni.internal
134+
@_$core.override
135+
String get signature => r'Lcom/example/in_app_java/R$mipmap;';
136+
137+
@_$jni.internal
138+
@_$core.override
139+
R_mipmap fromReference(_$jni.JReference reference) =>
140+
R_mipmap.fromReference(reference);
141+
142+
@_$jni.internal
143+
@_$core.override
144+
_$jni.JObjType get superType => const _$jni.JObjectType();
145+
146+
@_$jni.internal
147+
@_$core.override
148+
final superCount = 1;
149+
150+
@_$core.override
151+
int get hashCode => ($R_mipmap$Type).hashCode;
152+
153+
@_$core.override
154+
bool operator ==(Object other) {
155+
return other.runtimeType == ($R_mipmap$Type) && other is $R_mipmap$Type;
156+
}
157+
}
158+
159+
/// from: `com.example.in_app_java.R$style`
160+
class R_style extends _$jni.JObject {
161+
@_$jni.internal
162+
@_$core.override
163+
final _$jni.JObjType<R_style> $type;
164+
165+
@_$jni.internal
166+
R_style.fromReference(
167+
_$jni.JReference reference,
168+
) : $type = type,
169+
super.fromReference(reference);
170+
171+
static final _class =
172+
_$jni.JClass.forName(r'com/example/in_app_java/R$style');
173+
174+
/// The type which includes information such as the signature of this class.
175+
static const type = $R_style$Type();
176+
static final _id_LaunchTheme = _class.staticFieldId(
177+
r'LaunchTheme',
178+
r'I',
179+
);
180+
181+
/// from: `static public int LaunchTheme`
182+
static int get LaunchTheme =>
183+
_id_LaunchTheme.get(_class, const _$jni.jintType());
184+
185+
/// from: `static public int LaunchTheme`
186+
static set LaunchTheme(int value) =>
187+
_id_LaunchTheme.set(_class, const _$jni.jintType(), value);
188+
189+
static final _id_NormalTheme = _class.staticFieldId(
190+
r'NormalTheme',
191+
r'I',
192+
);
193+
194+
/// from: `static public int NormalTheme`
195+
static int get NormalTheme =>
196+
_id_NormalTheme.get(_class, const _$jni.jintType());
197+
198+
/// from: `static public int NormalTheme`
199+
static set NormalTheme(int value) =>
200+
_id_NormalTheme.set(_class, const _$jni.jintType(), value);
201+
}
202+
203+
final class $R_style$Type extends _$jni.JObjType<R_style> {
204+
@_$jni.internal
205+
const $R_style$Type();
206+
207+
@_$jni.internal
208+
@_$core.override
209+
String get signature => r'Lcom/example/in_app_java/R$style;';
210+
211+
@_$jni.internal
212+
@_$core.override
213+
R_style fromReference(_$jni.JReference reference) =>
214+
R_style.fromReference(reference);
215+
216+
@_$jni.internal
217+
@_$core.override
218+
_$jni.JObjType get superType => const _$jni.JObjectType();
219+
220+
@_$jni.internal
221+
@_$core.override
222+
final superCount = 1;
223+
224+
@_$core.override
225+
int get hashCode => ($R_style$Type).hashCode;
226+
227+
@_$core.override
228+
bool operator ==(Object other) {
229+
return other.runtimeType == ($R_style$Type) && other is $R_style$Type;
230+
}
231+
}
232+
233+
/// from: `com.example.in_app_java.R`
234+
class R extends _$jni.JObject {
235+
@_$jni.internal
236+
@_$core.override
237+
final _$jni.JObjType<R> $type;
238+
239+
@_$jni.internal
240+
R.fromReference(
241+
_$jni.JReference reference,
242+
) : $type = type,
243+
super.fromReference(reference);
244+
245+
static final _class = _$jni.JClass.forName(r'com/example/in_app_java/R');
246+
247+
/// The type which includes information such as the signature of this class.
248+
static const type = $R$Type();
249+
}
250+
251+
final class $R$Type extends _$jni.JObjType<R> {
252+
@_$jni.internal
253+
const $R$Type();
254+
255+
@_$jni.internal
256+
@_$core.override
257+
String get signature => r'Lcom/example/in_app_java/R;';
258+
259+
@_$jni.internal
260+
@_$core.override
261+
R fromReference(_$jni.JReference reference) => R.fromReference(reference);
262+
263+
@_$jni.internal
264+
@_$core.override
265+
_$jni.JObjType get superType => const _$jni.JObjectType();
266+
267+
@_$jni.internal
268+
@_$core.override
269+
final superCount = 1;
270+
271+
@_$core.override
272+
int get hashCode => ($R$Type).hashCode;
273+
274+
@_$core.override
275+
bool operator ==(Object other) {
276+
return other.runtimeType == ($R$Type) && other is $R$Type;
277+
}
278+
}
279+
37280
/// from: `androidx.emoji2.text.EmojiCompat$CodepointSequenceMatchResult`
38281
class EmojiCompat_CodepointSequenceMatchResult extends _$jni.JObject {
39282
@_$jni.internal

pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/util/ClassFinder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ public static <E> boolean findFilesInJar(
119119
jar.stream().map(JarEntry::getName).collect(Collectors.toCollection(TreeSet::new));
120120
boolean foundClassesInThisJar = false;
121121
for (var fqn : classes.keySet()) {
122-
if (classes.get(fqn) != null) { // already found
123-
continue;
124-
}
125122
var resultPaths = findClassAndChildren(entryNames, fqn, jarSeparator, suffix);
126123
if (resultPaths.isPresent()) {
127124
var jarEntries = resultPaths.get().stream().map(jar::getEntry).collect(Collectors.toList());
128-
classes.put(fqn, mapper.apply(jar, jarEntries));
125+
classes.putIfAbsent(fqn, new ArrayList<>());
126+
classes.get(fqn).addAll(mapper.apply(jar, jarEntries));
129127
foundClassesInThisJar = true;
130128
}
131129
}

0 commit comments

Comments
 (0)