Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/jni/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 1.0.1-wip

- Updates the minimum supported SDK version to Flutter 3.44/Dart 3.12.
- Migrates to built-in Kotlin.
- Improve error message when JNI is used before Flutter plugin initialization.
- Improve no such method error handling.
- Fix memory leaks and deadlocks that can happen in callbacks, if the target
Expand Down
16 changes: 14 additions & 2 deletions pkgs/jni/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ rootProject.allprojects {

apply plugin: 'com.android.library'

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
if (agpMajor < 9) {
apply plugin: 'kotlin-android'
}

android {
// Keeping the classes from being removed by proguard.
defaultConfig {
Expand Down Expand Up @@ -67,11 +72,18 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

defaultConfig {
minSdk 21
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}

36 changes: 18 additions & 18 deletions pkgs/jni/bin/setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ Future<void> runCommand(

class Options {
Options(ArgResults arg)
: buildPath = arg[_buildPath] as String?,
sources = arg[_srcPath] as List<String>,
packages = arg[_packageName] as List<String>,
cmakeArgs = arg[_cmakeArgs] as List<String>,
verbose = (arg[_verbose] as bool?) ?? false;
: buildPath = arg[_buildPath] as String?,
sources = arg[_srcPath] as List<String>,
packages = arg[_packageName] as List<String>,
cmakeArgs = arg[_cmakeArgs] as List<String>,
verbose = (arg[_verbose] as bool?) ?? false;

String? buildPath;
List<String> sources;
Expand Down Expand Up @@ -169,7 +169,8 @@ void main(List<String> arguments) async {
..addMultiOption(
_packageName,
abbr: 'p',
help: 'package for which native'
help:
'package for which native'
'library should be built',
)
..addFlag(_verbose, abbr: 'v', help: 'Enable verbose output')
Expand Down Expand Up @@ -212,7 +213,8 @@ void main(List<String> arguments) async {
}

final currentDirUri = Uri.directory('.');
final buildPath = options.buildPath ??
final buildPath =
options.buildPath ??
currentDirUri.resolve(_defaultRelativeBuildPath).toFilePath();
final buildDir = Directory(buildPath);
await buildDir.create(recursive: true);
Expand All @@ -234,13 +236,10 @@ void main(List<String> arguments) async {
stderr.writeln('Target newer than source, skipping build.');
} else {
verboseLog('Running gradle task for building jni sources to $buildPath.');
await runCommand(
gradleWExecutable.toFilePath(windows: isWin),
[
'jar',
'-Pjni.targetDir=${buildDir.absolute.uri.toFilePath(windows: isWin)}',
],
await findSources('jni', 'java'));
await runCommand(gradleWExecutable.toFilePath(windows: isWin), [
'jar',
'-Pjni.targetDir=${buildDir.absolute.uri.toFilePath(windows: isWin)}',
], await findSources('jni', 'java'));
}

for (var srcPath in sources) {
Expand Down Expand Up @@ -282,16 +281,17 @@ void main(List<String> arguments) async {
cmakeArgs.add(srcDir.absolute.path);
await runCommand('cmake', cmakeArgs, tempDir.path);
await runCommand('cmake', ['--build', '.'], tempDir.path);
final dllDirUri =
Platform.isWindows ? tempDir.uri.resolve('Debug') : tempDir.uri;
final dllDirUri = Platform.isWindows
? tempDir.uri.resolve('Debug')
: tempDir.uri;
final dllDir = Directory.fromUri(dllDirUri);
for (var entry in dllDir.listSync()) {
verboseLog(entry.toString());
final dllSuffix = Platform.isWindows
? 'dll'
: Platform.isMacOS
? 'dylib'
: 'so';
? 'dylib'
: 'so';
if (entry.path.endsWith(dllSuffix)) {
final dllName = entry.uri.pathSegments.last;
final target = buildDir.uri.resolve(dllName);
Expand Down
Loading
Loading