Create Basic4Android Libraries - Step by Step Tutorial
I. Introduction.
Welcome to my step-by-step tutorial about creating a Basic4Android Library.
First, I would like to thank Erel a lot for making this wonderful application. It’s really one of the best and easiest programs to use for making as well easy as complex android programs. Normally I never buy something on the internet, but this really did change my mind.
II. Eclipse
Ok, So how do we start on creating a library.
First you should start by downloading Eclipse. Eclipse is a multi-language software development environment comprising an integrated development environment (IDE). It is written mostly in Java and can be used to develop applications in Java, Android and more. You can download Eclipse here:
Eclipse - The Eclipse Foundation open source community website. > Eclipse Classic > and select the download (for 32 or 64 bit). What’s good about Eclipse is that you don’t have to install it, and you can just open the program.
When Eclipse is downloaded, double-click the map and open ‘Eclipse’. This could take some time to load.
Image 1: ImageShack® - Online Photo and Video Hosting
III. Setting up your first library.
Now the IDE is open. Select File > New > Java Project. A pop-up window will appear.
Image 2: ImageShack® - Online Photo and Video Hosting
Enter a project name, this could be anything, the JRE should be JavaSE 1-6 and click on Finish. Now your project name should appear at the left Panel called Package Explorer. Locate your Project Name and press the left arrow next to it. You will see 2 items. Right-click on ‘src’ > new > class.
Image 3: ImageShack® - Online Photo and Video Hosting
A new popup window will appear. Enter the <Name> of the class and don’t forget to also enter a package name. It’s a must to fill in these 2 things. This should be something like example.example. this is your unique identifier.
Image 4: ImageShack® - Online Photo and Video Hosting
And press finish. Now you would have something like
Now you are almost ready, but first we have to link some java archive (jar) files to get it work with android. These are: Android.jar, B4AShared.jar and I always include Core.jar but this is optional. But now we locate them. It’s good to copy them all three in one map, otherwise you have to locate them for every project. I just add a map called ‘Additional Libraries’ in my Anywhere Software map. Ok, so the first .jar file is android. The android.jar file is located here: <android-folder>\platforms\android-4.
If you don't see android-4 then you need to download the SDK with the SDK manager: Android SDK | Android Developers. Then the 2 files is B4AShared.jar and core.jar, you can find these in the Basic4Android Library folder.
Image 5: ImageShack® - Online Photo and Video Hosting
IV. Configure your library.
Now you have the 3 java archive files, go back to Eclipse and right click on your project name in the Package explorer and select Build Path > add external libraries and locate your three jar files.
Image 6: ImageShack® - Online Photo and Video Hosting
Ok, that’s basically everything u need for started programming, but now u also need to know how to export the .jar and .xml file. This is not so hard.
- For the XML File:
In Eclipse, go to Project > Generate Javadoc. Again a new window will popup saying “Generate Javadoc.” In javadoc command: locate your javadoc.exe. mine is: C:\Program Files (x86)\Java\jdk1.6.0_21\bin\javadoc.exe. Make sure you select the right one and don’t just copy mine.
Next check the checkbox next to the library you want to convert. Visibility: public and select the radiobutton saying: use custom doclet. Doclet Name: “BADoclet” and Doclet class path: “C:\Program Files (x86)\Anywhere Software\Doclet“ both without the quotes. Remember that the path may be different from yours.
Image 7: ImageShack® - Online Photo and Video Hosting
Then click on next. In the extra javadoc options u type the following:
-b4atarget "C:\Program Files (x86)\Anywhere Software\Additional Libraries\Example.xml"
Additional Libraries is a map I created myself for all my libraries I make. Change Example.xml with your own output name that will appear in b4Android IDE and click finish. Now the XML file has been created.
Image 8: ImageShack® - Online Photo and Video Hosting
- For the JAR File:
Click on File > Export > and look for JAR file in the Java Map.
Image 9: ImageShack® - Online Photo and Video Hosting
Select it and press next. Now select the resource you want to output, here we use Example.jar and check the box. And in the export destination, you browse for the map. I use C:\Program Files (x86)\Anywhere Software\Additional Libraries\Example.jar. Mmake sure the name is equal as the XML File, except the extension. Click on finish.
Image 10: ImageShack® - Online Photo and Video Hosting
U are almost ready with your first library. What u now have to do every time is copying the xml and jar file from your additional library map to the Library map of anywhere software. You have to keep exporting the xml and jar file and moving it to the new map. (I use another map so if I accidently overwrite another one.)
Congratulations, You are done creating your library. Now go to Basic4Android, click the library tab at the right bottom of the screen, right-click above it( so not on the tab itself) and choose refresh. Now your library should have been added. Also don’t forget that every time you replace your libraries that you have to refresh the library list, otherwise you will keep having your current library using.
Image 11: ImageShack® - Online Photo and Video Hosting
V. Some basic codes.
I will go deeper in my SoundRecorder library and try to explain some codes.
With a public void, you will be able to create your own codes. For example
Record.saveState(…) will execute the code under it.
I hope you understand everything in this tutorial, and if not, ask questions under here.
if i forgot something, please PM me and sorry if I made some english mistakes.
Thank you very much
XverhelstX
I. Introduction.
Welcome to my step-by-step tutorial about creating a Basic4Android Library.
First, I would like to thank Erel a lot for making this wonderful application. It’s really one of the best and easiest programs to use for making as well easy as complex android programs. Normally I never buy something on the internet, but this really did change my mind.
II. Eclipse
Ok, So how do we start on creating a library.
First you should start by downloading Eclipse. Eclipse is a multi-language software development environment comprising an integrated development environment (IDE). It is written mostly in Java and can be used to develop applications in Java, Android and more. You can download Eclipse here:
Eclipse - The Eclipse Foundation open source community website. > Eclipse Classic > and select the download (for 32 or 64 bit). What’s good about Eclipse is that you don’t have to install it, and you can just open the program.
When Eclipse is downloaded, double-click the map and open ‘Eclipse’. This could take some time to load.
Image 1: ImageShack® - Online Photo and Video Hosting
III. Setting up your first library.
Now the IDE is open. Select File > New > Java Project. A pop-up window will appear.
Image 2: ImageShack® - Online Photo and Video Hosting
Enter a project name, this could be anything, the JRE should be JavaSE 1-6 and click on Finish. Now your project name should appear at the left Panel called Package Explorer. Locate your Project Name and press the left arrow next to it. You will see 2 items. Right-click on ‘src’ > new > class.
Image 3: ImageShack® - Online Photo and Video Hosting
A new popup window will appear. Enter the <Name> of the class and don’t forget to also enter a package name. It’s a must to fill in these 2 things. This should be something like example.example. this is your unique identifier.
Image 4: ImageShack® - Online Photo and Video Hosting
And press finish. Now you would have something like
B4X:
package example.example;
public class example {
}
If you don't see android-4 then you need to download the SDK with the SDK manager: Android SDK | Android Developers. Then the 2 files is B4AShared.jar and core.jar, you can find these in the Basic4Android Library folder.
Image 5: ImageShack® - Online Photo and Video Hosting
IV. Configure your library.
Now you have the 3 java archive files, go back to Eclipse and right click on your project name in the Package explorer and select Build Path > add external libraries and locate your three jar files.
Image 6: ImageShack® - Online Photo and Video Hosting
Ok, that’s basically everything u need for started programming, but now u also need to know how to export the .jar and .xml file. This is not so hard.
- For the XML File:
In Eclipse, go to Project > Generate Javadoc. Again a new window will popup saying “Generate Javadoc.” In javadoc command: locate your javadoc.exe. mine is: C:\Program Files (x86)\Java\jdk1.6.0_21\bin\javadoc.exe. Make sure you select the right one and don’t just copy mine.
Next check the checkbox next to the library you want to convert. Visibility: public and select the radiobutton saying: use custom doclet. Doclet Name: “BADoclet” and Doclet class path: “C:\Program Files (x86)\Anywhere Software\Doclet“ both without the quotes. Remember that the path may be different from yours.
Image 7: ImageShack® - Online Photo and Video Hosting
Then click on next. In the extra javadoc options u type the following:
-b4atarget "C:\Program Files (x86)\Anywhere Software\Additional Libraries\Example.xml"
Additional Libraries is a map I created myself for all my libraries I make. Change Example.xml with your own output name that will appear in b4Android IDE and click finish. Now the XML file has been created.
Image 8: ImageShack® - Online Photo and Video Hosting
- For the JAR File:
Click on File > Export > and look for JAR file in the Java Map.
Image 9: ImageShack® - Online Photo and Video Hosting
Select it and press next. Now select the resource you want to output, here we use Example.jar and check the box. And in the export destination, you browse for the map. I use C:\Program Files (x86)\Anywhere Software\Additional Libraries\Example.jar. Mmake sure the name is equal as the XML File, except the extension. Click on finish.
Image 10: ImageShack® - Online Photo and Video Hosting
U are almost ready with your first library. What u now have to do every time is copying the xml and jar file from your additional library map to the Library map of anywhere software. You have to keep exporting the xml and jar file and moving it to the new map. (I use another map so if I accidently overwrite another one.)
Congratulations, You are done creating your library. Now go to Basic4Android, click the library tab at the right bottom of the screen, right-click above it( so not on the tab itself) and choose refresh. Now your library should have been added. Also don’t forget that every time you replace your libraries that you have to refresh the library list, otherwise you will keep having your current library using.
Image 11: ImageShack® - Online Photo and Video Hosting
V. Some basic codes.
I will go deeper in my SoundRecorder library and try to explain some codes.
B4X:
package xtremelyvirtualstudios.xvs.Sound;
//This is your package name.
B4X:
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
// these are all your imports that you need for some codes. If you seem to have an error on some code (red line under it), right click on it and see if there’s a import function.
B4X:
@ShortName("AudioRecorder") // this is the name as it appear on the IDE
// for example dim record as AudioRecorder
@Permissions(values = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.RECORD_AUDIO"}) // Permissions must always be declared otherwise your app or library won’t work. Just search on the internet what permissions you need to use.
@Author("XverhelstX") / / your name
@Version(1f) // the version
B4X:
public class SoundRecorder implements OnCompletionListener, OnErrorListener {
/**
* Saves the state of the current recording. IDLE_STATE = 0, RECORDING_STATE = 1 or PLAYING_STATE = 2
*
*/
public void saveState(Bundle recorderState) {
recorderState.putString(SAMPLE_PATH_KEY, mSampleFile.getAbsolutePath());
recorderState.putInt(SAMPLE_LENGTH_KEY, mSampleLength);
}
// the /** tags will give information about the code. This will appear under the code. When you type. (in B4Android)
/**
* Gets the maximum amplitude.
*
*/
public int getMaxAmplitude() {
if (mState != RECORDING_STATE)
return 0;
return mRecorder.getMaxAmplitude();
}
With a public void, you will be able to create your own codes. For example
Record.saveState(…) will execute the code under it.
I hope you understand everything in this tutorial, and if not, ask questions under here.
if i forgot something, please PM me and sorry if I made some english mistakes.
Thank you very much
XverhelstX
Last edited: