Skip to content

[jnigen] Fixed an issue with how java.io.File is created #2196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions pkgs/jnigen/example/pdfbox_plugin/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ On a Linux machine, following commands can be used to run the example applicatio
cd .. ## From this folder
dart run jnigen --config jnigen.yaml ## Downloads PDFBox JARs and generates bindings.
cd example/
dart run jni:setup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually required for the Flutter example at /example but is for the Dart-standalone example at /dart_example and the readme there already has it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running from IDE wouldn't require it, but running the built executable requires them. Please correct me if I'm wrong. Thanks. If it's too much, I will remove the line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure what you mean by running it from IDE. Flutter Linux build has a CMake that does the job of jni:setup making it unnecessary.

Yeah I would remove this line.

flutter run --release ## Opens the files list from home directory
```

Expand Down
9 changes: 4 additions & 5 deletions pkgs/jnigen/example/pdfbox_plugin/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class PDFInfoAppState extends State<PDFInfoApp> {
final isDir = (await item.stat()).type == FileSystemEntityType.directory;
if (item.path.endsWith('.pdf') && !isDir) {
pdfs.add(item.path);
} else if (isDir) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the example app shows all of directories even if the app aims to show the summary of pdf files found in $HOME directory. I thought better to exclude directories and included only pdf files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't created this example so I don't know what has been the purpose of this. I'm fine with not removing these lines as it doesn't make the example non-functional.

Feel free to open another PR that deletes this line (and cleans the unused variables as a result of your change) that explains why you are making this change. I'd rather this PR remains focused on solving the bug that you fixed.

dirs.add(item.path);
}
}
setState(() {
Expand Down Expand Up @@ -158,9 +156,10 @@ class PDFFileInfo {
// Since java.io is not directly available, use package:jni API to
// create a java.io.File object.
final fileClass = JClass.forName("java/io/File");
final inputFile = fileClass
.constructorId("(Ljava/lang/String;)V")
.call(fileClass, JObject.type, [filename]);
final fileConstructor = fileClass.constructorId("(Ljava/lang/String;)V");
final inputFile = fileConstructor(
fileClass, JObject.type, [JString.fromString(filename)]);

// Static method call PDDocument.load -> PDDocument
final pdf = PDDocument.load(inputFile)!;
// Instance method call getNumberOfPages() -> int
Expand Down
Loading