Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Implement suggestions in PR Review 1
Browse files Browse the repository at this point in the history
  * Add TODO in workflow for windows
  * Move jni_bindings_generated.dart to lib/src/third_party
  * Best effort punctuation in README
  * Add TODO for vendoring package in pubspec
  * Add AOSP license in preamble of jni_bindings_generated.dart
  • Loading branch information
mahesh-hegde committed Jul 11, 2022
1 parent 2fa0c92 commit 7e443a2
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ jobs:
parallel: true
path-to-lcov: ./jni_gen/coverage/lcov.info

## TODO: More minimal test on windows after fixing dev dependency.
## i.e do not rerun analyze and format steps, and do not require flutter.

test_jni:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./jni
steps:
- uses: actions/checkout@v3
## Requires flutter to analyze example.
## Using dart alone doesn't work.
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand Down
8 changes: 4 additions & 4 deletions jni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This library contains:

* functions to access the JNIEnv and JavaVM variables from JNI, and wrapper functions to those provided by JNI. (`Jni.getEnv`, `Jni.getJavaVM`).

* Functions to spawn a JVM on desktop platforms. (`Jni.spawn`)
* Functions to spawn a JVM on desktop platforms (`Jni.spawn`).

* Some utility functions to make it easier to work with JNI in Dart; eg: To convert a java string object to Dart string. (mostly as extension methods on `Pointer<JniEnv>`)
* Some utility functions to make it easier to work with JNI in Dart; eg: To convert a java string object to Dart string (mostly as extension methods on `Pointer<JniEnv>`).

* Some Android-specific helpers. (get application context and current activity references).
* Some Android-specific helpers (get application context and current activity references).

* Some helper classes and functions to simplify one-off uses. (`JniObject` and `JniClass` intended for calling functions by just specifying the name and arguments. It will reduce some boilerplate when you're debugging. That said, this API is slightly incomplete.)
* Some helper classes and functions to simplify one-off uses (`JniObject` and `JniClass` intended for calling functions by specifying the name and arguments. It will reduce some boilerplate when you're debugging. Note: this API is slightly incomplete).

This is intended for one-off / debugging uses of JNI, as well as providing a base library for code generated by jni_gen.

Expand Down
31 changes: 29 additions & 2 deletions jni/ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ description: |
However, functions prefixed JNI_ are not usable because they are in a different shared library.
Regenerate bindings with `flutter pub run path_to_ffigen.dart --config ffigen.yaml`.
output: 'lib/src/jni_bindings_generated.dart'
Regenerate bindings with `flutter pub run ffigen.dart --config ffigen.yaml`.
output: 'lib/src/third_party/jni_bindings_generated.dart'
headers:
entry-points:
- 'src/dartjni.h'
Expand Down Expand Up @@ -67,6 +67,33 @@ typedefs:
'jvalue': 'JValue'
preamble: |
// Autogenerated file. Do not edit.
// Generated from an annotated version of jni.h provided in Android NDK
// (NDK Version 23.1.7779620)
// The license for original file is provided below:
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* JNI specification, as defined by Sun:
* http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html
*
* Everything here is expected to be VM-neutral.
*/
// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
// ignore_for_file: non_constant_identifier_names
Expand Down
2 changes: 1 addition & 1 deletion jni/lib/jni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ export 'src/jni.dart';
export 'src/jvalues.dart' hide JValueArgs, toJValues;
export 'src/extensions.dart'
show StringMethodsForJni, CharPtrMethodsForJni, AdditionalJniEnvMethods;
export 'src/jni_bindings_generated.dart'; // currently just export all
export 'src/third_party/jni_bindings_generated.dart'; // currently export all
2 changes: 1 addition & 1 deletion jni/lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:ffi';

import 'package:ffi/ffi.dart';

import 'jni_bindings_generated.dart';
import 'third_party/jni_bindings_generated.dart';

extension StringMethodsForJni on String {
/// Returns a Utf-8 encoded Pointer<Char> with contents same as this string.
Expand Down
2 changes: 1 addition & 1 deletion jni/lib/src/jni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:io';
import 'package:ffi/ffi.dart';
import 'package:path/path.dart';

import 'jni_bindings_generated.dart';
import 'third_party/jni_bindings_generated.dart';
import 'extensions.dart';
import 'jvalues.dart';

Expand Down
2 changes: 1 addition & 1 deletion jni/lib/src/jni_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:ffi';

import 'package:ffi/ffi.dart';

import 'jni_bindings_generated.dart';
import 'third_party/jni_bindings_generated.dart';
import 'extensions.dart';
import 'jvalues.dart';
import 'jni_object.dart';
Expand Down
2 changes: 1 addition & 1 deletion jni/lib/src/jni_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:ffi';

import 'package:ffi/ffi.dart';

import 'jni_bindings_generated.dart';
import 'third_party/jni_bindings_generated.dart';
import 'extensions.dart';
import 'jni_class.dart';
import 'jvalues.dart';
Expand Down
2 changes: 1 addition & 1 deletion jni/lib/src/jvalues.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';

import 'jni_bindings_generated.dart';
import 'third_party/jni_bindings_generated.dart';
import 'extensions.dart';
import 'jni_object.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
// Autogenerated file. Do not edit.
// Generated from an annotated version of jni.h provided in Android NDK
// (NDK Version 23.1.7779620)
// The license for original file is provided below:

/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* JNI specification, as defined by Sun:
* http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html
*
* Everything here is expected to be VM-neutral.
*/

// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
// ignore_for_file: non_constant_identifier_names
Expand All @@ -17,7 +44,7 @@ import 'dart:ffi' as ffi;
///
/// However, functions prefixed JNI_ are not usable because they are in a different shared library.
///
/// Regenerate bindings with `flutter pub run path_to_ffigen.dart --config ffigen.yaml`.
/// Regenerate bindings with `flutter pub run ffigen.dart --config ffigen.yaml`.
///
class JniBindings {
/// Holds the symbol lookup function.
Expand Down
2 changes: 2 additions & 0 deletions jni/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dev_dependencies:
#
## After running `dart run ffigen --config ffigen.yaml` there
## should be no changes.
##
## TODO: vendor ffigen fork
ffigen:
git: https://github.com/mahesh-hegde/ffigen_patch_jni.git
#path: third_party/ffigen_patch
Expand Down

0 comments on commit 7e443a2

Please sign in to comment.