Help creating a native library(.so file)

268 views
Skip to first unread message

sunxuc...@163.com

unread,
Dec 20, 2016, 10:02:07 PM12/20/16
to App Inventor Open Source Development
Hello !

 I want to create a native library which is written by C language and then I can use this native library to create a component extension. I have read the MIT document "How to add a component" and the post of Gareth Haylings, But there is little information about the way to create the native library.They all about how to include the native library. I tryed many times,but failed. who knows the rules to create the Native library(*.so file) and the way to use it.Can you give me some tips?

Thank you in advance! Chen.

Jos Flores

unread,
Dec 21, 2016, 6:41:02 AM12/21/16
to app-inventor-open-source-dev
Hi Chen,

I don't think many people on here have tried to build native
libraries. We have used them from time to time, as in Gareth's posts,
and there's support to use them within the system, but for tips about
how to create them, you probably need to look for help in forums about
the Android NDK and such. All the best!

cheers,
José
> --
> You received this message because you are subscribed to the Google Groups
> "App Inventor Open Source Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to app-inventor-open-so...@googlegroups.com.
> To post to this group, send email to
> app-inventor-o...@googlegroups.com.
> Visit this group at
> https://groups.google.com/group/app-inventor-open-source-dev.
> For more options, visit https://groups.google.com/d/optout.

sunxuc...@163.com

unread,
Dec 22, 2016, 4:16:24 AM12/22/16
to App Inventor Open Source Development
Hi Jos,

Thanks very much for your reply.

I can create native library(**.so file)  by  using  Android NDK  on AndroidStudio.  I add it to the java source file.It can be complied into a  **.aix file. Then I import it into the app Inventor 2 ,it can not be compiled into  ***.apk file. Now I describe the whole process to you.Is there something wrong in my process? May be I need much more help.

Thanks in advance. Chen.

My source file are at the url  https://drive.google.com/drive/my-drive . My process are as follows.


First
     I create the  nativeLibraryTest.java file  .It is the extension component source file.It locates under the directory
C:\Users\pera\appinventor-sources\appinventor\components\src\cn\yzzyz\extensions.


Second 
    I add the native java code in my source file.




Third
     I use AndroidStudio to build the NativeLibrary. According to the package name and the class name in my source file.I create the same package and the class in AndroidStudio. Then I create the native library(**.so file) in AndroidStudio. 



Fourth
       I copy the folder armeabi and armeabi-v7a to the directory C:\Users\pera\appinventor-sources\appinventor\lib.Then I add " @UsesNativeLibraries(libraries = "libNdkJniDemo.so" ,v7aLibraries = "libNdkJniDemo.so") "and "String t = getStringFromC()" to the source file. I also add codes in appinventor-sources\appinventor\build.xml,in\appinventor-sources\appinventor\components\build.xml,in \appinventor-sources\appinventor\buildserver\build.xml.All thses can be found in the following pictures.

in C:\Users\pera\appinventor-sources\appinventor\build.xml

in C:\Users\pera\appinventor-sources\appinventor\components\build.xml

\


In C:\Users\pera\appinventor-sources\appinventor\buildserver

Then in C:\Users\pera\appinventor-sources\appinventor,I excute the order "ant extensions",it can build successfully.


The last .I import the **.aix file to the appInventor2,in can not be compiled into the apk file.













在 2016年12月21日星期三 UTC+8下午7:41:02,Jos写道:
Hi Chen,

I don't think many people on here have tried to build native
libraries. We have used them from time to time, as in Gareth's posts,
and there's support to use them within the system, but for tips about
how to create them, you probably need to look for help in forums about
the Android NDK and such. All the best!

cheers,
José



On 21 December 2016 at 03:02,  <sunxuc...@163.com> wrote:
> Hello !
>
>  I want to create a native library which is written by C language and then I
> can use this native library to create a component extension. I have read the
> MIT document "How to add a component" and the post of Gareth Haylings, But
> there is little information about the way to create the native library.They
> all about how to include the native library. I tryed many times,but failed.
> who knows the rules to create the Native library(*.so file) and the way to
> use it.Can you give me some tips?
>
> Thank you in advance! Chen.
>
> --
> You received this message because you are subscribed to the Google Groups
> "App Inventor Open Source Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
nativeLibraryTest.java

Evan Patton

unread,
Dec 29, 2016, 10:48:00 AM12/29/16
to App Inventor Open Source Development
Hi Chen,

This could be a sign of a bug in the extensions code. Could you send the AIX file that gets generated so we can take a look on our end?

Thanks,
Evan
Message has been deleted

sunxuc...@163.com

unread,
Jan 4, 2017, 3:55:16 AM1/4/17
to App Inventor Open Source Development
Hi Evan,

Thanks for your reply.
I put the AIX file to the attachment.When I generated the AIX file ,I got some warnings. So,I also upload the warning picture.
Thank you for your help!
Chen




在 2016年12月29日星期四 UTC+8下午11:48:00,Evan Patton写道:
cn.yzzyz.extensions.nativeLibraryTest.aix

Taifun

unread,
Mar 14, 2017, 5:21:08 PM3/14/17
to App Inventor Open Source Development
is there any progress on this? or do I have a different issue?

I now also tried to add a native library into an extension... building the aix file works fine, but while calling a method I get the following error 


 aix file is attached...

Taifun
com.puravidaapps.TaifunFilter.aix
Message has been deleted
Message has been deleted
Message has been deleted

Evan Patton

unread,
Mar 29, 2017, 4:24:34 PM3/29/17
to App Inventor Open Source Development
Hi Taifun,

I've been looking into this. It looks as though the extensions generator code doesn't actually pick up any resources other than the class files (e.g., there is no .so in your AIX file). I'll see what I can do about a fix but my guess is that if this is broken, its likely the build server hasn't been properly accounting for it either. We won't know until extensions are packaged correctly.

Evan

Gareth Haylings

unread,
Mar 31, 2017, 3:23:11 PM3/31/17
to App Inventor Open Source Development
Hi Evan

This will be so cool if you get native library support work on extension.

I was really wanting to make my Sphero component an extension when the CDK was first release but at it didnt support .so files i was not able to

look forward to you progress on this

cheers
Garetha

Yaw Owusu-Sarpong

unread,
Mar 9, 2018, 11:37:42 AM3/9/18
to App Inventor Open Source Development
Hi Evans,

Was there any fix for this please.

challen...@gmail.com

unread,
Nov 16, 2018, 4:48:36 AM11/16/18
to App Inventor Open Source Development
any news about this subject . @UsesNativeLibraries still not working

Evan Patton

unread,
Nov 16, 2018, 3:22:54 PM11/16/18
to App Inventor Open Source Development
We have a change pending that fixes native libraries for the core system. There will need to be a separate fix that addresses it for extensions. We are also not clear at the moment whether we are able to support native libraries in extensions from a live development perspective, since they likely need to be in a read-only part of the app-private storage to be loadable by System.loadLibrary().

Regards,
Evan
Reply all
Reply to author
Forward
0 new messages