Native Library Generator 4.20 (2018-11-11)
Written in B4J, this program allows you to write or import C/C++ code and have all the functions compiled into a native (.so) library, which in turn is included in a ready-to-use B4A Java lib. When using already existing code, if present, the main() function will be automatically ignored. If you're familiar with C/C++ but not with JNI or NDK, this is the right tool for you! No JAVA required.
Requirements:
Open Source:
This project is open source, under the GNU General Public License. Enjoy!
https://gitlab.com/brunowonder/NativeLibraryGenerator-CommunityEdition
https://gitlab.com/brunowonder/NativeLibraryGenerator-CommunityEdition
Price (pay what you want):
If you wish to buy me a beer (or even dinner!) just follow the link below.
https://www.paypal.me/ninjadynamics
https://www.paypal.me/ninjadynamics
How does it work:
Video Demos:
Updates:
[Version 4.21] [2018-11-12] [CRITICAL]
QuickSource mode fixed
For background music add "nlg.mp3" to the NLG folder
QuickSource mode fixed
For background music add "nlg.mp3" to the NLG folder
[Version 4.20] [2018-11-11] [NEW FEATURES]
Now supporting multiple source files
Select which files should be exposed to B4A
Requires NDK r18b (please update)
Bug fixes
Now supporting multiple source files
Select which files should be exposed to B4A
Requires NDK r18b (please update)
Bug fixes
[Version 4.01] [2017-05-07] [NEW FEATURES]
The 'cpu-features' library can now be used
Custom Makefiles may now be used
Custom Java wrappers may now be used
Bug fixes
The 'cpu-features' library can now be used
Custom Makefiles may now be used
Custom Java wrappers may now be used
Bug fixes
[Version 4.00] [2017-05-07] [NEW FEATURES]
Complete visual overhaul
Specifying additional include paths is now possible
Specifying additional prebuilt libraries is now possible
Specifying the target ABI's is now possible
Compatible ABI's are now auto-detected if possible
Handling multiple projects is now possible
Complete visual overhaul
Specifying additional include paths is now possible
Specifying additional prebuilt libraries is now possible
Specifying the target ABI's is now possible
Compatible ABI's are now auto-detected if possible
Handling multiple projects is now possible
[Version 3.0] [2017-05-07] [NEW FEATURES]
Returning arrays is now possible.
B4A logging with printf() is now possible.
[Version 2.9] [2016-08-12] [NEW FEATURES]
Small UI redesign and bug fixes.
Code clean-up.
Little bit more user-friendly.
Custom makefiles.
Returning arrays is now possible.
B4A logging with printf() is now possible.
[Version 2.9] [2016-08-12] [NEW FEATURES]
Small UI redesign and bug fixes.
Code clean-up.
Little bit more user-friendly.
Custom makefiles.
[Version 2.8] [2016-07-12] [NEW FEATURES]
Now supporting local #include files.
Now supporting external project locations.
New video demo.
Minor bug fixes.
Now supporting local #include files.
Now supporting external project locations.
New video demo.
Minor bug fixes.
[Version 2.7] [2016-03-14] [CRITICAL]
Major bug fixes.
Major bug fixes.
[Version 2.6] [2016-01-31] [IMPORTANT]
Important bug fixes.
MazeSolver 1.5 Included as example source code.
[Version 2.5] [2016-01-31] [NEW FEATURES]
Now supporting comment transcription from C++ to B4A.
New splash screen.
Minor bug fixes.
Important bug fixes.
MazeSolver 1.5 Included as example source code.
[Version 2.5] [2016-01-31] [NEW FEATURES]
Now supporting comment transcription from C++ to B4A.
New splash screen.
Minor bug fixes.
[Version 2.4] [2016-01-27] [CRITICAL]
Critical bug fix regarding string (char*) support.
Cool new intro/exit screens added.
[Version 2.3] [2016-01-25] [NEW FEATURES]
Now supporting Strings (char*), both passing and returning.
Critical bug fix regarding string (char*) support.
Cool new intro/exit screens added.
[Version 2.3] [2016-01-25] [NEW FEATURES]
Now supporting Strings (char*), both passing and returning.
[Version 2.2] [2016-01-20] [IMPORTANT]
Now supporting simple C/C++ typedef struct.
Now supporting C/C++ inline functions.
Minor bug fixes.
[Version 2.1] [2016-01-12] [CRITICAL]
Included example (NinjaCore) source code updated. Several bug fixes.
Now supporting simple C/C++ typedef struct.
Now supporting C/C++ inline functions.
Minor bug fixes.
[Version 2.1] [2016-01-12] [CRITICAL]
Included example (NinjaCore) source code updated. Several bug fixes.
[Version 2.1] [2016-01-12] [IMPORTANT]
Now supporting C++ headers, such as <vector> or <algorithm>.
Now supporting C++ headers, such as <vector> or <algorithm>.
[Version 2.0] [2016-01-10] [CRITICAL]
Major issue corrected. Please download Native Library Generator again.
Major issue corrected. Please download Native Library Generator again.
Included Example:
In order to showcase this software's capabilities, I decided to include my MazeSolver project.
A. Download link:
B. Instructions (QuickSource Mode):
In QuickSouce mode all you have to do is write some code and hit the Generate Library button.
1. Before anything else, please make sure you have installed the following required software:
B4A, Simple Library Compiler and Android NDK
2. Download the .jar file into a system-writable folder (NOT Program Files).
B4A, Simple Library Compiler and Android NDK
2. Download the .jar file into a system-writable folder (NOT Program Files).
3. Run NLG and provide the necessary software paths, as seen below.
4. Compile the example by clicking the big blue button.
5. Test the library you just compiled with this B4A project:
https://www.b4x.com/android/forum/t...orithm-w-path-optimization.61998/#post-391230
4. Compile the example by clicking the big blue button.
5. Test the library you just compiled with this B4A project:
https://www.b4x.com/android/forum/t...orithm-w-path-optimization.61998/#post-391230
6. As you can see, it works!
C. LibFastMath Example code (Copy/Paste to NLG):
B4X:
//LibFastMath 1.00 - Native Library Example
//FastSin() and FastCos() by Allen Chou
//http://allenchou.net/2014/02/game-math-faster-sine-cosine-with-polynomial-curves
//FastSqrt() adapted from Quake 3's Fast Inverse Square Root algorithm
//https://en.wikipedia.org/wiki/Fast_inverse_square_root
#define PI (3.1415926535f)
#define HALF_PI (0.5f * PI)
#define TWO_PI (2.0f * PI)
#define TWO_PI_INV (1.0f / TWO_PI)
float FastSin(float x);
float FastCos(float x);
float FastSqrt(float x);
inline float Hill(float x)
{
const float a0 = 1.0f;
const float a2 = 2.0f / PI - 12.0f / (PI * PI);
const float a3 = 16.0f / (PI * PI * PI) - 4.0f / (PI * PI);
const float xx = x * x;
const float xxx = xx * x;
return a0 + a2 * xx + a3 * xxx;
}
float FastSin(float x)
{
// wrap x within [0, TWO_PI)
const float a = x * TWO_PI_INV;
x -= static_cast<int>(a) * TWO_PI;
if (x < 0.0f)
x += TWO_PI;
// 4 pieces of hills
if (x < HALF_PI)
return Hill(HALF_PI - x);
else if (x < PI)
return Hill(x - HALF_PI);
else if (x < 3.0f * HALF_PI)
return -Hill(3.0f * HALF_PI - x);
else
return -Hill(x - 3.0f * HALF_PI);
}
float FastCos(float x)
{
return FastSin(x + HALF_PI);
}
float FastSqrt(float x)
{
//This is the method used in Quake3
const float xhalf = 0.5f*x;
//Get bits for floating value
union
{
float x;
int i;
} u;
u.x = x;
//Give initial guess y0
u.i = 0x5f3759df - (u.i >> 1);
//Newton step, repeating increases accuracy
return (x*u.x*(1.5f - xhalf*u.x*u.x));
}
D. How does it work:
Initially, I created this program in order to speed-up the process of writing JNI C/C++ code. Following B4A's RAD philosophy, it allows me to write native code in Visual Studio and compile it into a fully-working B4A lib within a single click.
E. Internal Functions:
If you wish any of your native function not to be exposed in the B4A library, you may do so by either changing their name from foo() into privateFoo() or simply adding a "::ignore" the function's comments.
F. Current Limitations:
B4X:
//This function will not be visible in B4A because its name starts with "private".
int privateSum(int a, int b)
{
return a + b;
}
//This function will not be visible in B4A because this comment contains the keyword "::ignore".
int multiplication(int a, int b)
{
return a * b;
}
//This function will be exposed in B4A.
int result(int a, int b)
{
return privateSum(a, b) + multiplication(a, b);
}
As happy as I am to share this work with the B4x community, let's not forget that this is just my own internal tool, a never ending work-in-progress personal project.
Hence, it does not yet support several features such as passing Arrays into the native layer.
G. Reminder:Hence, it does not yet support several features such as passing Arrays into the native layer.
Please test your C/C++ code before trying to build a B4A library, as some kinds of syntax errors may crash the application.
Attachments
Last edited: