Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing native code in eclipse android application
    primarykey
    data
    text
    <p>I have an android application project in eclipse and I need to be able to create gif files from bitmaps. So after searching around, I found out that there is some <a href="http://jiggawatt.org/badc0de/android/index.html#gifflen" rel="nofollow">C/C++ code</a> to do exactly this. My problem is that I don't know how to import this code into my project. I've looked around and I believe I'm supposed to add a JAR file to the library build path, but I have no JAR file, only a few C/C++ files (see link). </p> <p>I have zero experience with C/C++ and am only using it for creating gif files. Basically I'm wondering if someone can guide me in being able to use the C/C++ code. I've tried installing NDK and cygwin, but don't know what else to do. Here's the code I've tried, but it failed because it cannot locate gifflen.</p> <pre><code>static { System.loadLibrary("gifflen"); } public native int Init(String gifName, int w, int h, int numColors, int quality, int frameDelay); public native void Close(); public native int AddFrame(int[] inArray); public void download(DrawCanvas canvas) { String path = DOWNLOADS_PATH + File.separator + mName + ".gif"; int width = canvas.getWidth(); int height = canvas.getHeight(); int result = Init(path, width, height, 256, 100, 4); if (result == 0) { List&lt;AbstractShape&gt; oldShapes = canvas.getShapes(); for (Page page : mPages) { canvas.setShapes(page.getShapes()); Bitmap bitmap = canvas.getBitmap(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); AddFrame(pixels); } canvas.setShapes(oldShapes); Close(); } else { Log.d("DEBUG", "init failed"); } } </code></pre> <p>I've created a jni folder in my project folder and placed all the files from the link inside it. The files are:</p> <ul> <li>Android.mk</li> <li>dib.c</li> <li>dib.h</li> <li>gifflen.cpp</li> <li>neuquant.h</li> </ul> <p>Any help would be greatly appreciated. Thanks!!</p> <p>Edit:</p> <p>I've tried what you said, I replaced the Android.mk code with what you provided and created a Source and Include folder. I placed all .c and .cpp files in Source and .h in Include and left the Android.mk outside, in the jni directory. But I still got this error in logcat when I tried to run:</p> <pre><code>08-12 02:33:14.834: E/AndroidRuntime(8563): FATAL EXCEPTION: main 08-12 02:33:14.834: E/AndroidRuntime(8563): java.lang.ExceptionInInitializerError 08-12 02:33:14.834: E/AndroidRuntime(8563): at edu.foothill.myflipbook.MainActivity.onCreate(MainActivity.java:35) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.app.Activity.performCreate(Activity.java:4524) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2189) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.app.ActivityThread.access$600(ActivityThread.java:139) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.os.Handler.dispatchMessage(Handler.java:99) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.os.Looper.loop(Looper.java:154) 08-12 02:33:14.834: E/AndroidRuntime(8563): at android.app.ActivityThread.main(ActivityThread.java:4894) 08-12 02:33:14.834: E/AndroidRuntime(8563): at java.lang.reflect.Method.invokeNative(Native Method) 08-12 02:33:14.834: E/AndroidRuntime(8563): at java.lang.reflect.Method.invoke(Method.java:511) 08-12 02:33:14.834: E/AndroidRuntime(8563): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 08-12 02:33:14.834: E/AndroidRuntime(8563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 08-12 02:33:14.834: E/AndroidRuntime(8563): at dalvik.system.NativeStart.main(Native Method) 08-12 02:33:14.834: E/AndroidRuntime(8563): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gifflen: findLibrary returned null 08-12 02:33:14.834: E/AndroidRuntime(8563): at java.lang.Runtime.loadLibrary(Runtime.java:365) 08-12 02:33:14.834: E/AndroidRuntime(8563): at java.lang.System.loadLibrary(System.java:535) 08-12 02:33:14.834: E/AndroidRuntime(8563): at edu.foothill.myflipbook.Flipbook.&lt;clinit&gt;(Flipbook.java:33) 08-12 02:33:14.834: E/AndroidRuntime(8563): ... 15 more </code></pre> <p>I tried ndk-build in cmd, but got this error instead:</p> <pre><code>Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersi on 11 in ./AndroidManifest.xml Android NDK: jni/Android.mk: Cannot import module with spaces in tag: '' Android NDK: jni/Android.mk: Cannot find module with tag '' in import path Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ? Android NDK: The following directories were searched: Android NDK: jni/Android.mk:9: *** Android NDK: Aborting. . Stop. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload