NDK issue, pure native apps like NativeActivity compile but are not transferred to the device.

2,957 views
Skip to first unread message

Ronnie van Aarle

unread,
Sep 8, 2011, 2:06:21 PM9/8/11
to android-ndk
Hello NDK,

I have found an issue in the packaging routine that generates .apk
files from pure native apps, apps compiled into lib<application>.so
that are executed directly from the Dalvic VM java runtime.

With several examples, NativeActivity from the NDK samples, and also
the examples native_lorenz and native_globe I had the same problem.

Clicking from eclipse on my android device caused the app to crash
before being executed. logcat showed:

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.nvidia.devtech.NativeLorenz/
android.app.NativeActivity}: java.lang.IllegalArgumentException:
Unable to find native library: native_lorenz

and also:

AndroidRuntime(17879): Caused by: java.lang.IllegalArgumentException:
Unable to find native library: native_lorenz

In this post "NativeActivity app fails to run" I found the same
problem, and for some reason, in rusty's errormessage, there was also
a path shown to the location where this shared object was expected.

Yesterday I rooted my device, so I went to look in the corresponding
location for my native_lorentz, and I found that the file indeed was
not there. After manually copying libnative_lorentz.so from $PROJECT/
native_lorentz/libs/armeabi-v7a/libs/ to /data/data/com.nvidia.devtech/
lib/ the application did execute and run without anymore problems.

Regards, Ronnie van Aarle.

Doug .

unread,
Sep 9, 2011, 2:40:51 AM9/9/11
to andro...@googlegroups.com
I take it you unzipped your .apk file and checked you had those files in your /lib/ directory in the archive?

When I've hit this issue it has been without fail because I forgot to copy the latest versions of the library into the /lib/ directory and they were therefore missing in the apk, and then missing on the device some the application was installed... 

~
Doug.

mikelong

unread,
Nov 3, 2011, 5:42:52 PM11/3/11
to android-ndk
I'm having this exact problem, but have found a workaround. I
recently updated my rooted OG MotoDroid to Peter Alfonso's 2.3.7 from
his 2.3.4 Gingerbread build and this started happening with the native-
activity example. When I would try to install the apk everything
would appear fine, but it would force close immediately with the
message:

E/AndroidRuntime(10460): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.example.native_activity/
android.app.NativeActivity}: java.lang.IllegalArgumentException:
Unable to find native library: native-activity

Sure enough, when I look in /data/data/com.example.native_activity/lib
it is completely empty. If I push libnative-activity.so over there by
hand, it starts working.

After banging my head on this longer than I care to admit, I
discovered that the following fixes it for the native activity
example..

Change android:hasCode="true" in AndroidManifest.xml

make sure the src directory is present and totally empty.. i.e. rm -rf
src/*

Then build the apk like normal (I'm not using Eclipse, so don't know
if it will work there)..

ant debug install

I have no idea why this works, but frankly I'm just happy it does. As
I mentioned above, I'm on a rooted phone running 2.3.7 and the problem
only showed up when I made the switch from 2.3.4.

Maybe someone smarter than me can figure out the root cause...

Cheers,

Mike


On Sep 8, 1:06 pm, Ronnie van Aarle <ronnie.van.aa...@gmail.com>
wrote:
> Hello NDK,
>
> I have found an issue in the packaging routine that generates .apk
> files from purenativeapps, apps compiled into lib<application>.so
> that are executed directly from the Dalvic VM java runtime.
>
> With several examples, NativeActivity from the NDK samples, and also
> the examples native_lorenz and native_globe I had the same problem.
>
> Clicking from eclipse on my android device caused the app to crash
> before being executed. logcat showed:
>
> java.lang.RuntimeException: Unable to startactivity
> ComponentInfo{com.nvidia.devtech.NativeLorenz/
> android.app.NativeActivity}: java.lang.IllegalArgumentException:
> Unable to findnativelibrary: native_lorenz
>
> and also:
>
> AndroidRuntime(17879): Caused by: java.lang.IllegalArgumentException:
> Unable to findnativelibrary: native_lorenz

bryanturley

unread,
Nov 9, 2011, 3:36:13 PM11/9/11
to android-ndk
+1 on that.

Same problem switched hasCode to true and it worked.
Compiling from a shell not eclipse.

Eric

unread,
Dec 8, 2011, 10:41:20 PM12/8/11
to android-ndk
THANK YOU FOR THIS ANSWER

I have been stuck on this for months, had completely written off
NativeActivity because the sample didn't even work!!!

> > With several examples,NativeActivityfrom the NDK samples, and also


> > the examples native_lorenz and native_globe I had the same problem.
>
> > Clicking from eclipse on my android device caused the app to crash
> > before being executed. logcat showed:
>
> > java.lang.RuntimeException: Unable to startactivity
> > ComponentInfo{com.nvidia.devtech.NativeLorenz/
> > android.app.NativeActivity}: java.lang.IllegalArgumentException:
> > Unable to findnativelibrary: native_lorenz
>
> > and also:
>
> > AndroidRuntime(17879): Caused by: java.lang.IllegalArgumentException:
> > Unable to findnativelibrary: native_lorenz
>

> > In this post "NativeActivityapp fails to run" I found the same

Justin Buser

unread,
Jan 6, 2012, 9:45:19 AM1/6/12
to android-ndk
> > I have no idea why this works, but frankly I'm just happy it does.  As
> > I mentioned above, I'm on a rooted phone running 2.3.7 and the problem
> > only showed up when I made the switch from 2.3.4.
>
> > Maybe someone smarter than me can figure out the root cause...
>

I think the reason this example instructs you to set hasCode to false
is that the libnative-activity.so file is intended to be dropped into
another application as it can be called/started using an Intent just
like any other activity. The AndroidManifest.xml file really shouldn't
be part of the example however unless it was more concisely
documented. As far as I can tell setting hasCode to false on the
application tag in the Manifest essentially causes the APK to do
nothing at all, not sure what the point is but it is certainly
confusing.

Dianne Hackborn

unread,
Jan 7, 2013, 2:34:39 AM1/7/13
to andro...@googlegroups.com
On Fri, Jan 6, 2012 at 6:45 AM, Justin Buser <jus...@justinbuser.com> wrote:
I think the reason this example instructs you to set hasCode to false
is that the libnative-activity.so file is intended to be dropped into
another application as it can be called/started using an Intent just
like any other activity. The AndroidManifest.xml file really shouldn't
be part of the example however unless it was more concisely
documented.  As far as I can tell setting hasCode to false on the
application tag in the Manifest essentially causes the APK to do
nothing at all, not sure what the point is but it is certainly
confusing.

android:hasCode means that the .apk has no dalvik code; it is instructing the framework to not try to add the app's dalvik code to its class path when initializing its process (which would fail if there wasn't any dalvik code to load).  The example is using this simply to illustrate that if you are using NativeActivity, you don't need to have any dalvik code in your apk at all, since NativeActivity is implemented in the framework.  In practice most applications will not do this, because they will often want to have a subclass of NativeActivity with some customization or other activities or services or such.

--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.
Reply all
Reply to author
Forward
0 new messages