Skip to content

Commit 5741f2c

Browse files
Merge package:jni and package:jnigen into shared native repository
2 parents c64e9c8 + a063c40 commit 5741f2c

File tree

590 files changed

+88877
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

590 files changed

+88877
-0
lines changed

.github/workflows/jnigen.yaml

Lines changed: 428 additions & 0 deletions
Large diffs are not rendered by default.

pkgs/jni/.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.packages
30+
build/
31+
32+
.vscode/

pkgs/jni/.metadata

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: 676cefaaff197f27424942307668886253e1ec35
8+
channel: stable
9+
10+
project_type: plugin_ffi
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 676cefaaff197f27424942307668886253e1ec35
17+
base_revision: 676cefaaff197f27424942307668886253e1ec35
18+
- platform: android
19+
create_revision: 676cefaaff197f27424942307668886253e1ec35
20+
base_revision: 676cefaaff197f27424942307668886253e1ec35
21+
- platform: linux
22+
create_revision: 676cefaaff197f27424942307668886253e1ec35
23+
base_revision: 676cefaaff197f27424942307668886253e1ec35
24+
- platform: macos
25+
create_revision: 676cefaaff197f27424942307668886253e1ec35
26+
base_revision: 676cefaaff197f27424942307668886253e1ec35
27+
- platform: windows
28+
create_revision: 676cefaaff197f27424942307668886253e1ec35
29+
base_revision: 676cefaaff197f27424942307668886253e1ec35
30+
31+
# User provided section
32+
33+
# List of Local paths (relative to this file) that should be
34+
# ignored by the migrate tool.
35+
#
36+
# Files that are not part of the templates will be ignored by default.
37+
unmanaged_files:
38+
- 'lib/main.dart'
39+
- 'ios/Runner.xcodeproj/project.pbxproj'

pkgs/jni/CHANGELOG.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## 0.8.0-wip
2+
3+
- **Breaking Change** ([#394](https://github.com/dart-lang/jnigen/issues/394)):
4+
Converted various `Exception`s into `Error`s:
5+
- `UseAfterReleaseException` -> `UseAfterReleaseError`
6+
- `DoubleReleaseException` -> `DoubleReleaseError`
7+
- `SpawnException` -> `JniError` (It's now a `sealed class`)
8+
- `JNullException` -> `JNullError`
9+
- `InvalidCallTypeException` -> `InvalidCallTypeError`
10+
- `HelperNotFoundException` -> `HelperNotFoundError`
11+
- `JvmExistsException` -> `JniVmExistsError`
12+
- `NoJvmInstanceException` -> `NoJvmInstanceError`
13+
- **Breaking Change**: Removed `InvalidJStringException`.
14+
- **Breaking Change**: The default return `callType` of type parameter `int` for
15+
methods such as `JObject.callMethodByName<int>` is now Java's `long` instead
16+
of `int` to be consistent with the way arguments work.
17+
- **Breaking Change**: `JType` is now `sealed`.
18+
- **Breaking Change**: Primitive types and their type classes are now `final`.
19+
- **Breaking Change**: `JArray.filled` now uses the generated type class of the
20+
`fill` object and not its Java runtime type.
21+
22+
## 0.7.2
23+
- Fixed a bug where reading non-null terminated strings would overflow.
24+
25+
## 0.7.1
26+
- Removed macOS Flutter plugin until package:jni supports it ([#41](https://github.com/dart-lang/jnigen/issues/41)).
27+
28+
## 0.7.0
29+
30+
- **Breaking Change** ([#387](https://github.com/dart-lang/jnigen/issues/387)):
31+
Added `JBuffer` and `JByteBuffer` classes as default classes for
32+
`java.nio.Buffer` and `java.nio.ByteBuffer` respectively.
33+
- **Breaking Change**: Made the type classes `final`.
34+
- Fixed a bug where `addAll`, `removeAll` and `retainAll` in `JSet` would run
35+
their respective operation twice.
36+
- Fixed a bug where `JList.insertAll` would not throw the potentially thrown
37+
Java exception.
38+
39+
## 0.6.1
40+
41+
- Depend on the stable version of Dart 3.1.
42+
43+
## 0.6.0
44+
45+
- **Breaking Change** ([#131](https://github.com/dart-lang/jnigen/issues/131)):
46+
Renamed `delete*` to `release*`.
47+
- Added `PortProxy` and related methods used for interface implementation.
48+
- Added the missing binding for `java.lang.Character`.
49+
50+
## 0.5.0
51+
52+
- **Breaking Change** ([#137](https://github.com/dart-lang/jnigen/issues/137)):
53+
Java primitive types are now all lowercase like `jint`, `jshort`, ...
54+
- The bindings for `java.util.Set`, `java.util.Map`, `java.util.List` and the
55+
numeric types like `java.lang.Integer`, `java.lang.Boolean`, ... are now
56+
included in `package:jni`.
57+
58+
## 0.4.0
59+
60+
- Type classes now have `superCount` and `superType` getters used for type
61+
inference.
62+
63+
## 0.3.0
64+
65+
- Added `PortContinuation` used for `suspend fun` in Kotlin.
66+
- `dartjni` now depends on `dart_api_dl.h`.
67+
68+
## 0.2.1
69+
70+
- Added `.clang-format` to pub.
71+
72+
## 0.2.0
73+
74+
- Added array support
75+
- Added generic support
76+
- `JniX` turned into `JX` for a more terse code.
77+
78+
## 0.1.1
79+
80+
- Windows support for running tests and examples on development machines.
81+
82+
## 0.1.0
83+
84+
- Initial version: Android and Linux support, JObject API

pkgs/jni/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2022, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/jni/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# jni
2+
3+
This is a support library to access JNI from Dart / Flutter code. This provides the common infrastructure to bindings generated by [jnigen](https://pub.dev/packages/jnigen), as well as some utility methods.
4+
5+
This library contains:
6+
7+
* Functions to access the JNIEnv and JavaVM variables from JNI, and wrapper functions to those provided by JNI. JNIEnv is exposed via `GlobalJniEnv` type which provides a thin abstraction over JNIEnv, so that it can be used from multiple threads.
8+
* Functions to spawn a JVM on desktop platforms (`Jni.spawn`).
9+
* Some Android-specific helpers (get application context and current activity references).
10+
* `JObject` class, which provides base class for classes generated by jnigen.
11+
* Commonly used Java classes like `JList`, `JMap`, `JInteger`, ...
12+
13+
Apart from being the base library for code generated by `jnigen` this can also be used for one-off uses of the JNI and debugging. __To generate type-safe bindings from Java libraries, use `jnigen`.__
14+
15+
## Documentation
16+
The test/ directory contains files with comments explaining the basics of this module, and the example/ directory contains a flutter example which also touches some Android-specifics.
17+
18+
Using this library assumes some familiarity with JNI - it's threading model and object references, among other things.

pkgs/jni/analysis_options.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
analyzer:
4+
exclude: [build/**, third_party/**]
5+
language:
6+
strict-raw-types: true
7+
8+
linter:
9+
rules:
10+
- prefer_final_locals
11+
- prefer_const_declarations
12+
# Additional information about this file can be found at
13+
# https://dart.dev/guides/language/analysis-options

pkgs/jni/android/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx

pkgs/jni/android/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder contains the [Android plugin class](src/main/java/com/github/dart_lang/jni/JniPlugin.java) which takes care of initializing JNI on Android.

pkgs/jni/android/build.gradle

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// The Android Gradle Plugin builds the native code with the Android NDK.
2+
3+
group 'com.github.dart_lang.jni'
4+
version '1.0'
5+
6+
buildscript {
7+
ext.kotlin_version = '1.6.10'
8+
repositories {
9+
google()
10+
mavenCentral()
11+
}
12+
13+
dependencies {
14+
// The Android Gradle Plugin knows how to build native code with the NDK.
15+
classpath 'com.android.tools.build:gradle:7.1.2'
16+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17+
}
18+
}
19+
20+
rootProject.allprojects {
21+
repositories {
22+
google()
23+
mavenCentral()
24+
}
25+
}
26+
27+
apply plugin: 'com.android.library'
28+
29+
android {
30+
// Keeping the classes from being removed by proguard.
31+
defaultConfig {
32+
consumerProguardFiles 'consumer-rules.pro'
33+
}
34+
buildTypes {
35+
release {
36+
minifyEnabled false
37+
}
38+
}
39+
40+
// Condition for namespace compatibility in AGP 8
41+
if (project.android.hasProperty("namespace")) {
42+
namespace 'com.github.dart_lang.jni'
43+
}
44+
45+
// Adding [PortContinuation] and [PortProxy] classes shared between Flutter and
46+
// Dart-standalone versions of package:jni.
47+
sourceSets {
48+
main {
49+
java {
50+
srcDirs '../java/src/main/java'
51+
}
52+
}
53+
}
54+
55+
// Bumping the plugin compileSdkVersion requires all clients of this plugin
56+
// to bump the version in their app.
57+
compileSdkVersion 31
58+
59+
// Bumping the plugin ndkVersion requires all clients of this plugin to bump
60+
// the version in their app and to download a newer version of the NDK.
61+
// Note(MaheshH) - Flutter seems to download minimum NDK of flutter when
62+
// below line is commented out.
63+
// How about leaving it?
64+
// ndkVersion "21.1.6352462"
65+
66+
// Invoke the shared CMake build with the Android Gradle Plugin.
67+
externalNativeBuild {
68+
cmake {
69+
path "../src/CMakeLists.txt"
70+
71+
// The default CMake version for the Android Gradle Plugin is 3.10.2.
72+
// https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
73+
//
74+
// The Flutter tooling requires that developers have CMake 3.10 or later
75+
// installed. You should not increase this version, as doing so will cause
76+
// the plugin to fail to compile for some customers of the plugin.
77+
// version "3.10.2"
78+
}
79+
}
80+
81+
compileOptions {
82+
sourceCompatibility JavaVersion.VERSION_1_8
83+
targetCompatibility JavaVersion.VERSION_1_8
84+
}
85+
86+
defaultConfig {
87+
minSdkVersion 16
88+
}
89+
}

0 commit comments

Comments
 (0)