0

Hello I use Android NDK on Eclipse (Windows) to compile a C program (needed by my Android app). The file is compiled and the executable is created in libs/armeabi folder of my Android project, but when I run the app on the device, there's no trace of it.

The executable is fine, in fact if I rename it to libmyapp.so it's pushed correctly to /data/data/myapp/lib on the device.

Thank you.

the structure
  • 89
  • 1
  • 10
  • What do you mean "there's no trace of it."? You know it should be inside the APK. Do your NDK calls fail or work? – weston Sep 15 '15 at 12:20
  • Also I wouldn't use eclipse long term. Look to move to Android Studio ASAP. NDK takes some setting up, but all the help you need is here on SO, for example: http://stackoverflow.com/a/30641567/360211 – weston Sep 15 '15 at 12:23
  • NDK call succeds, the executable is created but not pushed on the device. If I choose BUILD_SHARED_LIBRARY instead of BUILD_EXECUTABLE, for example, libmyapp.so file is not only created in libs/armeabi in my project but also pushed in /data/data/myapp/lib folder on the device. – the structure Sep 15 '15 at 12:36
  • You should be creating a .so library and calling it from java. Not creating an executable. – weston Sep 15 '15 at 12:38
  • Perhaps you can explain why you are creating an executable and not a library. – weston Sep 15 '15 at 12:43
  • it's a command line tool. – the structure Sep 15 '15 at 13:01
  • But that's because you've compiled it as such. You could easily have a NDK method that invoked the same code as your Main method. – weston Sep 15 '15 at 13:03
  • Ok I'll try to change it to a library. – the structure Sep 15 '15 at 13:08
  • About Android Studio, I've already thought about moving to it but I'm in the middle of a project so I postponed the move to after project's deadline. – the structure Sep 15 '15 at 13:10
  • I recommend familiarizing yourself with https://developer.android.com/ndk/samples/sample_hellojni.html first and then you might be able to easily see how you can invoke your existing code as a library call. – weston Sep 15 '15 at 13:20
  • You also may want it to run on ARM, Intel etc, Well as a NDK library that's as simple as telling it to compile for all targets. One line. – weston Sep 15 '15 at 13:21

1 Answers1

0

If you build an executable, a command-line tool, it is up to you to install it on the device and make sure it's in the path. If you want to automate installation, you have two options:

1) write a script that would run on a PC (linux/windows/mac) and install your executable via adb.

2) write an Android GUI application, place the executable in its assets/ folder, and have the application unpack and install it on the first launch.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127