Out of the NDK path configuration channels, ndkVersion feature added in version 3.5 and above provides a major flexibility for applications: NDK dependency moves from project level to module level! We strongly recommend developers to take full advantage of the feature. The related available features that could affect which version of NDK to use are: The possible directories that AGP locates NDK are: Resource has an openRawResource() call to get the InputStream and an openRawResourceFd() call to get the file descriptor, as above, though.Classpath ':gradle:4.1.0-alpha02' If your file is a resource, you may need to go through the Resource class to access it, though it appears resources are also packed into the same assets package. This is a PITA because you can't query (AFAIK) the file size I run a preprocessing step on my assets folder that generates a list of all the files with their respective sizes so I can know, e.g., how big of a buffer to allocate. If your file is compressed, you need to use the Java streaming reader: AssetManager.open() gives you an InputStream you can use the read the file in. You're really getting a file handle to the entire assets package, and your file of interest is only a small part. Note you must fseek() to the offset, and keep track of the length of the file yourself. Then you can use fdopen(dup(fd),"r") to open the file as a FILE*. ![]() png), you can get a file descriptor from AssetManager.openFd() and pass it to C++. If the file wasn't compressed (i.e., it's one of the extensions that doesn't get compressed, like. File names are always relative to the assets folder, btw: If your have a file "foo.png" directly in the assets folder, you'd open "foo.png," not something like "assets/foo.png". Both use the AssetManager methods, and you can get the AssetManager from the context/app. In the assets folder case you need to do one of two things, depending on whether the file was compressed by the packager. I recommend, to avoid having to reinvent the wheel, that you stick any assets you want shipped with your app in the assets folder, where they'll be packaged up for distribution. I can also verify that fopen() works correctly, but not if you're trying to access a file in the application's resources or assets folder. Here is the result after running it on my phone (with an SD card): $ adb -d shell cat /sdcard/hello.txt ![]() Return (*env)->NewStringUTF(env, "Hello from JNI (with file io)!") Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,įILE* file = fopen("/sdcard/hello.txt","w+") * apps/samples/hello-jni/project/src/com/example/HelloJni/HelloJni.java * This is a trivial JNI example where we use a native method * See the License for the specific language governing permissions and ![]() * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * distributed under the License is distributed on an "AS IS" BASIS, * Unless required by applicable law or agreed to in writing, software * You may obtain a copy of the License at ![]() * you may not use this file except in compliance with the License. * Licensed under the Apache License, Version 2.0 (the "License") * Copyright (C) 2009 The Android Open Source Project Perhaps you are trying to open a file with a bad path and not checking the return code? I modified the hello-jni example to demonstrate that it is indeed possible to open file and write to it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |