Skip to content

Commit

Permalink
[jni] Fix jni on Android (#1955)
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi authored Jan 30, 2025
1 parent cf5b631 commit f65e2e5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pkgs/jni/lib/src/jni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ String _getLibraryFileName(String base) {
} else if (Platform.isMacOS) {
return 'lib$base.dylib';
} else {
throw UnsupportedError('cannot derive library name: unsupported platform');
throw UnsupportedError('Cannot derive library name: unsupported platform');
}
}

/// Load Dart-JNI Helper library.
///
/// If path is provided, it's used to load the library.
/// Else just the platform-specific filename is passed to DynamicLibrary.open
/// Loads dartjni helper library.
DynamicLibrary _loadDartJniLibrary({String? dir, String baseName = 'dartjni'}) {
final fileName = _getLibraryFileName(baseName);
final libPath = (dir != null) ? join(dir, fileName) : fileName;
final file = File(libPath);
if (!file.existsSync()) {
throw HelperNotFoundError(libPath);
var fileName = _getLibraryFileName(baseName);
if (!Platform.isAndroid) {
if (dir != null) {
fileName = join(dir, fileName);
}
final file = File(fileName);
if (!file.existsSync()) {
throw HelperNotFoundError(fileName);
}
}
try {
final dylib = DynamicLibrary.open(libPath);
return dylib;
return DynamicLibrary.open(fileName);
} catch (_) {
throw DynamicLibraryLoadError(libPath);
throw DynamicLibraryLoadError(fileName);
}
}

Expand Down

0 comments on commit f65e2e5

Please sign in to comment.