Android Tutorial [java] Creating libraries for B4A

rosippc64a

Active Member
Licensed User
Longtime User
@Erel
I am learning how to make a small lib. I did the video tutprial and I did the firstlib. No problem. Now I go on but I don't know how?
I have this code:
B4X:
@ShortName("First")
@Events(values={"Event (X As int)"})
@Version(1.01f)
public class First {
   ...
  protected Sometype createSecondClass() {
     BA.Log("ThisShown");
     return new Second();
   }
   public class Second {
   ...
   }
}
I can make jar and xml file, the b4a can see, and use too the things in First class part. But when I want to use a function (createSecondClass) from First what would like to initialise the Second class, then there is a noClassDefFoundError: First$Second. I have a First$Second.jar also, but I don't know what I have to say and where that b4a do know the Second class?

I made two different .java files for the two class, and I compiled to .jar.
When I compile the b4a project, the b4a can't access an imported class what there is in the before compiled .jar. B4a can show functions from .jar (because a good .xml), but can't compile.
 
Last edited:

rosippc64a

Active Member
Licensed User
Longtime User
I have one step ahead. The b4a can see the missing class. The solution was: I copied the lib having the class into b4a library folder. After it that was ok, but I didn't was satisfied that I don't know the real reason and I remove the lib from the folder, and remove a sign from eclipse's properties, where the ioiolib was checked and the result: b4a can't see the class again. How I can embed the neccessary lib into the jar that b4a can see?

 
Last edited:

rosippc64a

Active Member
Licensed User
Longtime User
Thank you DonManfred,
I did it. Works. After export I got a small size Firstlib.jar and I copied the ioiolib into the B4a additional library folder. Can I reference this lib such a mode that the ioiolib be packaged into Firstlib.jar?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
f I have a jar with dependency of "VALUES.XML"
do you have a jar or a aar?

If you have an aar:
Like i already told: extract the classes.jar from the aar and add it in eclipse to your buildpaths.use the aar filename in depends-on and copy the aar to additional libs folder.

If you have only a jar then you need to create a R.class in your wrapper like in b4a 5

Maybe you should upload your source (src, jar, aar) so we can see....

Or better: Create a new thread for your problem showing enough details/code to check...
 

DonManfred

Expert
Licensed User
Longtime User
Last edited:

JohnC

Expert
Licensed User
Longtime User
Before I dive into creating my first library, should I install and use Eclipse which this tutorial is based on, or should I use Android Studio instead?

And if I should use Android Studio, how different/difficult will it be to do the tutorial for it?
 

JohnC

Expert
Licensed User
Longtime User
Thanks for the input
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…