Build Fails with Android Library Project

114 views
Skip to first unread message

mobocr...@gmail.com

unread,
Aug 12, 2014, 4:20:37 PM8/12/14
to codenameone...@googlegroups.com
Hello Guys,

I am currently experiencing build errors when i add native library project. First the Android project is created on eclipse and built.Next i zip the entire project directory and rename it with the extension .andlib eg mobo.andlib. After which I put it in the android native directory of the codenameone netbeans project.the build error is attached.It does not seem to locate the native android project. I dont' know if I am doing the right thing with linking the android native library project with codenameone. Can anyone suggest the best way to do this?

Regards,
error (6).txt

mobocr...@gmail.com

unread,
Aug 12, 2014, 4:25:07 PM8/12/14
to codenameone...@googlegroups.com, mobocr...@gmail.com
Also, the android library project has some resources been used, I really need to understand the right way of doing this plus I will be adding the new PayPal Android SDK.

Shai Almog

unread,
Aug 13, 2014, 1:27:48 AM8/13/14
to codenameone...@googlegroups.com, mobocr...@gmail.com
Hi,
You can't just add a jar. You need to use native interfaces and place the logic there otherwise we won't be able to do anything with this on iOS etc.
See: http://www.codenameone.com/3/post/2013/07/jaring-and-libraries.html
For examples see the cn1libs http://www.codenameone.com/cn1libs.html

mobocreditinc

unread,
Aug 13, 2014, 1:32:22 AM8/13/14
to Shai Almog, codenameone...@googlegroups.com

Hi,

I did that and it worked on the source stub when used in eclipse. I expected it to work when moved to netbeans and zipped the entire android project library and saved it ending in .andlib imside the native folder for android in the codenameone netbeans project.

Regards.

mobocreditinc

unread,
Aug 13, 2014, 3:19:40 AM8/13/14
to Shai Almog, codenameone...@googlegroups.com

Hi,
Let me explain further, lets say you have a codenameone project and you need some sepecific native functionality on Android. You head to eclipse and create an Android Library Project that implements this functionality with a .so file. In addition you apply some styles/drawables and you test it and all is working fine. You head back to codenameone netbeans project and generate the native stub to bridge. Afterwhich you now send a build to the server and check include sources. The sources are now generated. You open it up in eclipse and link it to the android library project, update the manifest and all works fine. With this, your android native library project has proven to work fine. Now, you zip the entire android library project from the root folder and save it in a file name ending with .andlib. you put this file ajacent to the native stub in the android native directory of the codename one project e.g native/android/mobolib.andlib. Update the build hints to add the android.xapplication with the value of the activity in the library. Then off you go to the build server. Your expectation is that this should work as it did on the eclipse. But it fails with the new error:

Executing: /home/ec2-user/android-sdk/tools/android create project --target android-15 --name Main --path /tmp/build855721304908947123xxx/Main --activity MainStub --package com.mobocredit Created directory /tmp/build855721304908947123xxx/Main/src/com/mobocredit
Added file /tmp/build855721304908947123xxx/Main/src/com/mobocredit/MainStub.java
Created directory /tmp/build855721304908947123xxx/Main/res
Created directory /tmp/build855721304908947123xxx/Main/bin
Created directory /tmp/build855721304908947123xxx/Main/libs
Created directory /tmp/build855721304908947123xxx/Main/res/values
Added file /tmp/build855721304908947123xxx/Main/res/values/strings.xml
Created directory /tmp/build855721304908947123xxx/Main/res/layout
Added file /tmp/build855721304908947123xxx/Main/res/layout/main.xml
Created directory /tmp/build855721304908947123xxx/Main/res/drawable-hdpi
Created directory /tmp/build855721304908947123xxx/Main/res/drawable-mdpi
Created directory /tmp/build855721304908947123xxx/Main/res/drawable-ldpi
Added file /tmp/build855721304908947123xxx/Main/AndroidManifest.xml
Added file /tmp/build855721304908947123xxx/Main/build.xml
Added file /tmp/build855721304908947123xxx/Main/proguard-project.txt
Executing: /home/ec2-user/android/ant/bin/ant debug Buildfile: /tmp/build855721304908947123xxx/Main/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.2.1
 [checkenv] Installed at /home/ec2-user/android-sdk

-setup:
     [echo] Project Name: Main
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 18.1.1
     [echo] Resolving Build Target for Main...
[gettarget] Project Target:   Android 4.0.3
[gettarget] API level:        15
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /tmp/build855721304908947123xxx/Main/bin/res
    [mkdir] Created dir: /tmp/build855721304908947123xxx/Main/bin/rsObj
    [mkdir] Created dir: /tmp/build855721304908947123xxx/Main/bin/rsLibs
    [mkdir] Created dir: /tmp/build855721304908947123xxx/Main/gen
    [mkdir] Created dir: /tmp/build855721304908947123xxx/Main/bin/classes
    [mkdir] Created dir: /tmp/build855721304908947123xxx/Main/bin/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for Main...

BUILD FAILED
/home/ec2-user/android-sdk/tools/ant/build.xml:577: /dependency/src/ resolve to a path with no project.properties file for project /tmp/build855721304908947123xxx/Main

Total time: 1 second


of which in the library there exist a project.properties file 


Regards

Shai Almog

unread,
Aug 13, 2014, 10:38:06 AM8/13/14
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
Hi,
OK I see what you mean. You had an andlib file that worked for you in eclipse, just place the exact same file in NetBeans's native android directory.
It seems like you zipped the wrong root for NetBeans.

Akash Kubavat

unread,
Jan 7, 2015, 10:50:58 PM1/7/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
Hello @Shai ,

Sorry to interrupt in mid of the post,

Unfortunately I am landed at the same situation and didn't find a way to solve this issue.

I did all what is suggested above in this post.

Here are the steps..
- Created a library project in eclipse.
- Put .so files in lib folder and did clean and build.
- For testing purpose added that library project in another android project in eclipse, and that works fine..
- Now back in CN1 in Net Beans, I zipped that library project from eclipse
      -> like, my_project.zip contain /project_files
      -> like this way also, my_project.zip contain /parent directory/project_files
      (I'm not sure which method is correct so I tried by both of these ways, one by one)
- Rename my_project.zip to my_project.andlib
- Added this andlib file to native/android/ in CN1 project
- Sent android build to CN1 cloud and got errors like below:
     1) in case of /project_files
[echo] ----------
[echo] Resolving Dependencies for ItemSearchMain...

BUILD FAILED
/home/ec2-user/android-sdk/tools/ant/build.xml:577: /dependency/project.properties/ resolve to a path with no project.properties file for project /tmp/build4884553541710932188xxx/ItemSearchMain

Total time: 1 second

      2) in case of /parent_directory/project_files
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [aapt] invalid resource directory name: /tmp/build11990730733361854xxx/ItemSearchMain/dependency/ScanditSDKDemoSimple/bin/res/crunch

BUILD FAILED
/home/ec2-user/android-sdk/tools/ant/build.xml:601: The following error occurred while executing this line:
/home/ec2-user/android-sdk/tools/ant/build.xml:653: The following error occurred while executing this line:
/home/ec2-user/android-sdk/tools/ant/build.xml:698: null returned: 1

Total time: 2 seconds

I am not sure at which point I am doing wrong step.

Am I following correct sequence and correct method ?

Please can you give me some hint?

Thanks.

Shai Almog

unread,
Jan 8, 2015, 1:42:05 AM1/8/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
Hi,
Chen is probably more versed in this than I am. I've asked him to answer.

Chen Fishbein

unread,
Jan 8, 2015, 3:52:58 AM1/8/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
Hi,
Seems like it's a known issue with this lib you use:

Try to remove the bin directory before you zip it to andlib file

Akash Kubavat

unread,
Jan 8, 2015, 7:27:04 PM1/8/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com

@Chen
I tried that way you suggested and it solve above error.
But now I am getting another error saying UnsatisfiedLinkError

01-09 12:46:15.440: W/System.err(25952): java.lang.UnsatisfiedLinkError: Couldn't load sxxxx-xxxxxxxxxr-android-4.2.2 from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.wildwing.itemsearch-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.wildwing.itemsearch-1, /vendor/lib, /system/lib]]]: findLibrary returned null
01-09 12:46:15.448: W/System.err(25952):     at java.lang.Runtime.loadLibrary(Runtime.java:366)
01-09 12:46:15.451: W/System.err(25952):     at java.lang.System.loadLibrary(System.java:514)

Please see the image, files are there in /native/android/ directory

I tried by keeping only .andlib file and
by keeping .andlib & .jar file, for which logcat is giving error.

Both the time I am getting same error.

FYI:
if I open generated apk in winrar, it is showing me lib directory with
        - /lib/armeabi/my_lib.so
        - /lib/armeabi-v7a/my_lib.so
        - /lib/x86/my_lib.so
but not showing me .jar file
Whereas, if I check my library project's lib directory then it is having that .jar in it.
So that .jar library is not in apk, same thing that error is saying, I guess.

Any comment for this, please ?

Akash

Chen Fishbein

unread,
Jan 9, 2015, 6:49:50 AM1/9/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
Hi,
It's hard to tell what's not working, 
Did you managed to make this lib project work for a regular android project?
If yes, I'd suggest you to build with "include sources" then open the generated android project and try to build it locally and check what's the difference between the projects.

Akash Kubavat

unread,
Jan 11, 2015, 7:47:00 PM1/11/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
@Chen
Sorry I am in confusion by "include sources" suggestion..

So here I am writing the steps I am following to build and test library, kindly spot me when it goes wrong...

- I created library project MyLibrary in eclipse and mark it as a library by (Project -> property -> Android Tab -> Tick isLibrary)
- MyLibrary itself contain .so files in armeabi, armeabi-v7a and x86 directory and one .jar file in MyLibrary/lib directory and my functional source code files
- Now I created another TestDemo android application project.
- Add MyLibrary project as a library to TestDemo project by (Project -> property -> Android Tab -> Add -> select MyLibrary)
- I am calling my function from TestDemo project on button click that is written in MyLibrary source and it works well

- Now for CN1 I am removing MyLibrary's bin directory and its content and exporting the whole MyLibrary project as a zip.
- Renaming MyLibrary.zip to MyLibrary.andlib
- Adding this to /native/android/ directory
- Implemented native interface
- Native call works perfect from CN1 form (Tested by making a toast and works well)
- Now I re-code native function to call MyLibrary's function
- It compiles well, CN1 server gives apk back
- I install it and when call functionality on button
   it gives java.lang.UnsatisfiedLinkError
   voila...!

So did I miss any step/s ?

I searched for "how to generate build with 'include sources' " but I didn't find any satisfied workaround.

Thanks,
Akash

Chen Fishbein

unread,
Jan 12, 2015, 3:19:58 AM1/12/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
Hi,
Before sending the build to the build server right click on your project and mark the "include source" checkbox, once this is checked the build server will provide you a download link for the android generated project.
Grab the project sources from the build server and open this android project in eclipse (the .andlib should be located under <project>/dependency/), now try to compile it locally and see if it works and if not what went wrong.

Akash Kubavat

unread,
Jan 12, 2015, 11:01:06 PM1/12/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com

I download source code from server and have to do some modification in import statements in Eclipse..

I imported both the projects(second from the dependency) and
configure second as a library in main project manually (there was the project in library list but path was not discovered so)

I am able to run application but in Log it is giving following error
01-13 16:59:42.903: W/System.err(9987): java.lang.InstantiationException: can't instantiate class userclasses.customComponents.AndroidSMSInterface
01-13 16:59:42.910: W/System.err(9987):     at java.lang.Class.newInstanceImpl(Native Method)
01-13 16:59:42.910: W/System.err(9987):     at java.lang.Class.newInstance(Class.java:1319)
01-13 16:59:42.910: W/System.err(9987):     at com.codename1.system.NativeLookup.create(NativeLookup.java:52)
01-13 16:59:42.910: W/System.err(9987):     at userclasses.StateMachine.onAddnewInstance_ScanButtonAction(StateMachine.java:195)
01-13 16:59:42.910: W/System.err(9987):     at generated.StateMachineBase.handleComponentAction(StateMachineBase.java:2935)
01-13 16:59:42.910: W/System.err(9987):     at com.codename1.ui.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2824)
01-13 16:59:42.910: W/System.err(9987):     at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:338)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Button.fireActionEvent(Button.java:393)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Button.released(Button.java:424)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Button.pointerReleased(Button.java:512)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Form.pointerReleased(Form.java:2338)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Form.pointerReleased(Form.java:2274)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Component.pointerReleased(Component.java:2667)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Display.handleEvent(Display.java:1937)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Display.edtLoopImpl(Display.java:1029)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.Display.mainEDTLoop(Display.java:960)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
01-13 16:59:42.911: W/System.err(9987):     at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
01-13 16:59:42.911: W/System.err(9987):     at java.lang.Thread.run(Thread.java:838)
01-13 16:59:42.916: V/Provider/Settings(9987):  from settings cache , name = sound_effects_enabled , value = 0


Where in device screen is remaining just as it is, no popup, no error nothing / no effect on screen, but log is giving error...

thanks.

Shai Almog

unread,
Jan 13, 2015, 2:10:57 AM1/13/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com
The implementation of the native interface must not have a constructor other than a public default constructor.
It should remain a public class.
Message has been deleted

Akash Kubavat

unread,
Jan 13, 2015, 6:37:53 PM1/13/15
to codenameone...@googlegroups.com, shai....@gmail.com, mobocr...@gmail.com

I got it worked..
all thanks to

@shai and @chen

for supporting and giving continuous reply

love u codename one and codename team..

Regards,
Reply all
Reply to author
Forward
0 new messages