how can we integrate babylon native in exisiting ios application
Hi @jasshu_garg welcome to the forum
yes, you can see the playground example provided here : BabylonNative/Apps/Playground at master · BabylonJS/BabylonNative · GitHub
Hi @Cedric , i am able to run these independently , i want to integrate it in my exisiting android and ios applications , how to do that?
copy these files in your project:
these 2:
these 1:
and
Add the BabylonView in your app like this activity:
and update build gradle with externalNativeBuild:
And that should be enough. Let me know how it goes.
Hi, thanks for the reply ,
i am getting some issues , in updating gradle file , can you please guide a little for what to be updated in gradle
Add and adapt this in the android/default config section:
and this in android section:
and then the copy files section
Thanks for the information.
I still have some doubts , , in this part of the code ( BabylonJS/BabylonNative/blob/master/Apps/Playground/Android/app/build.gradle#L117-L154) . we are referring to the node module files , which are not present in my current android application
I am also getting this error , even though following your instructions ,
C/C++: CMake Error at CMakeLists.txt:11 (add_subdirectory):
i have tried putting CMakeLists.txt at these paths
app2/app/src/main/cpp/CMakeLists.txt
app2/app/CMakeLists.txt
this is my gradle file :
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}
val jsEngine = project.findProperty("jsEngine")?.toString() ?: "V8" // This will allow fetching the property if it exists, else will default to "V8"
val graphicsApi: String = project.findProperty("GRAPHICS_API")?.toString() ?: "OpenGL"
var platformVersion = if (graphicsApi == "Vulkan") 24 else 21 // Set platform version based on graphics API
val unityBuild: String = project.findProperty("UNITY_BUILD")?.toString() ?: "false"
val arcoreLibPath = "${buildDir}/arcore-native"
android {
namespace = "com.example.myapplication2"
compileSdk = 34
defaultConfig {
applicationId = "com.example.myapplication2"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
abiFilters.addAll(listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64"))
arguments(
"-DANDROID_STL=c++_shared",
"-DENABLE_PCH=OFF",
"-DGRAPHICS_API=$graphicsApi",
"-DARCORE_LIBPATH=$arcoreLibPath/jni",
"-DNAPI_JAVASCRIPT_ENGINE=$jsEngine",
"-DBABYLON_NATIVE_BUILD_APPS=ON",
"-DCMAKE_UNITY_BUILD=$unityBuild",
"-DBABYLON_DEBUG_TRACE=ON"
)
}
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt") // Update this path to your CMakeLists.txt
}
}
packagingOptions {
jniLibs {
pickFirsts.addAll(listOf("lib/*/libv8android.so", "lib/*/libjsc.so"))
}
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}
tasks.register<Copy>("copyFiles") {
// Copy from the BabylonJS package
from("../../../node_modules/babylonjs") {
include("babylon.max.js")
}
into("src/main/assets/Scripts")
// Copy from the BabylonJS loaders package
from("../../../node_modules/babylonjs-loaders") {
include("babylonjs.loaders.js")
}
into("src/main/assets/Scripts")
// Copy from the BabylonJS materials package
from("../../../node_modules/babylonjs-materials") {
include("babylonjs.materials.js")
}
into("src/main/assets/Scripts")
// Copy from the BabylonJS GUI package
from("../../../node_modules/babylonjs-gui") {
include("babylon.gui.js")
}
into("src/main/assets/Scripts")
// Copy from the Dependencies folder
from("../../../Dependencies") {
include("*.js")
}
into("src/main/assets/Scripts")
// Copy from the Scripts folder
from("../../Scripts") {
include("*.js")
}
into("src/main/assets/Scripts")
}
Update:
Task :app:buildCMakeDebug[x86_64] FAILED
C/C++: ninja: Entering directory `/path/app2/app/.cxx/Debug/1c392t39/x86_64’
C/C++: /Users/jasshugarg/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=x86_64-none-linux-android24 --sysroot=/Users/jasshugarg/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DBabylonNativeJNI_EXPORTS -I"/path/Shared" -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-limit-debug-info -fPIC -std=gnu++17 -MD -MT CMakeFiles/BabylonNativeJNI.dir/src/main/cpp/BabylonNativeJNI.cpp.o -MF CMakeFiles/BabylonNativeJNI.dir/src/main/cpp/BabylonNativeJNI.cpp.o.d -o CMakeFiles/BabylonNativeJNI.dir/src/main/cpp/BabylonNativeJNI.cpp.o -c ‘path/app2/app/src/main/cpp/BabylonNativeJNI.cpp’
C/C++: path/app2/app/src/main/cpp/BabylonNativeJNI.cpp:12:10: fatal error: ‘AndroidExtensions/Globals.h’ file not found
C/C++: #include <AndroidExtensions/Globals.h>
C/C++: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C/C++: 1 error generated.
BabylonNative source must be accessible. you can either add a subrepo using git or use cmake fetch :
https://cmake.org/cmake/help/latest/module/FetchContent.html
fatal error: ‘AndroidExtensions/Globals.h’ file not found
#include <AndroidExtensions/Globals.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this error persists
is the dependency set in cmake like her ?
is it fetched by cmake like here ?
AndroidExtensions is solved , but another like “BabylonNative” , that’s still missing
#include <Babylon/AppRuntime.h>
#include <Babylon/Graphics/Device.h>
#include <Babylon/ScriptLoader.h>
#include <Babylon/Plugins/NativeEngine.h>
#include <Babylon/Plugins/NativeInput.h>
#include <Babylon/Plugins/NativeXr.h>
#include <Babylon/Plugins/NativeCamera.h>
#include <Babylon/Plugins/NativeOptimizations.h>
#include <Babylon/Polyfills/Console.h>
#include <Babylon/Polyfills/Window.h>
#include <Babylon/Polyfills/XMLHttpRequest.h>
#include <Babylon/Polyfills/Canvas.h>
#include "Babylon/DebugTrace.h"
these are missing
I have only these folders in my Build folder , all the other directories are missing ,
app2/Build/Android/Debug/3j5o2c39/x86/_deps/
├── androidextensions-build
├── androidextensions-src
├── androidextensions-subbuild
├── arcana.cpp-build
├── arcana.cpp-src
├── arcana.cpp-subbuild
├── babylonnative-build
├── babylonnative-src
├── babylonnative-subbuild
└── cmakeextensions-build
└── cmakeextensions-src
└── cmakeextensions-subbuild
All these <Babylon/...
are part of babylonnative-src
Hi @Cedric ,
I am getting this error while launching playground activity from my android app ,
Drawing frame
2024-10-03 16:30:45.382 17230-17230 BabylonView com.example.myapplication2 D Drawing frame
2024-10-03 16:30:45.394 17230-17230 BabylonView com.example.myapplication2 D Drawing frame
2024-10-03 16:30:45.412 17311-17311 DEBUG pid-17311 A Process name is com.example.myapplication2, not key_process
2024-10-03 16:30:45.412 17311-17311 DEBUG pid-17311 A Cmdline: com.example.myapplication2
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A pid: 17230, tid: 17308, name: Thread-10 >>> com.example.myapplication2 <<<
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #02 pc 0000000000b62878 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #03 pc 0000000000b62684 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (void std::__ndk1::vector<TIntermNode*, glslang::pool_allocator<TIntermNode*> >::__construct_at_end<TIntermNode**, 0>(TIntermNode**, TIntermNode**, unsigned long)+88) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #04 pc 0000000000b62464 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #05 pc 0000000000b5ff6c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (glslang::TVector<TIntermNode*>::TVector(glslang::TVector<TIntermNode*> const&)+28) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #06 pc 0000000000b5fd54 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (glslang::TIntermAggregate::updatePrecision()+156) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #07 pc 0000000000b8928c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (glslang::TParseContext::addConstructor(glslang::TSourceLoc const&, TIntermNode*, glslang::TType const&)+1672) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #08 pc 0000000000b8a574 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (glslang::TParseContext::handleFunctionCall(glslang::TSourceLoc const&, glslang::TFunction*, TIntermNode*)+372) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #09 pc 0000000000bbe550 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (yyparse(glslang::TParseContext*)+3180) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #10 pc 0000000000b83768 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (glslang::TParseContext::parseShaderStrings(glslang::TPpContext&, glslang::TInputScanner&, bool)+76) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #11 pc 0000000000b72418 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #12 pc 0000000000b7038c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #13 pc 0000000000b6bc4c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #14 pc 0000000000b6d394 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (glslang::TShader::parse(TBuiltInResource const*, int, EProfile, bool, bool, EShMessages, glslang::TShader::Includer&)+412) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #15 pc 0000000000931d0c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (glslang::TShader::parse(TBuiltInResource const*, int, EProfile, bool, bool, EShMessages)+112) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #16 pc 0000000000931270 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #17 pc 0000000000930c98 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (Babylon::ShaderCompiler::Compile(std::__ndk1::basic_string_view<char, std::__ndk1::char_traits<char> >, std::__ndk1::basic_string_view<char, std::__ndk1::char_traits<char> >)+116) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #18 pc 00000000008cb15c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (Babylon::NativeEngine::CreateProgramInternal(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >)+376) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #19 pc 0000000000902e28 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #20 pc 00000000009025c0 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #21 pc 0000000000902458 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #22 pc 0000000000902344 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #23 pc 0000000000902210 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #24 pc 00000000009034e4 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (stdext::inplace_function<arcana::basic_expected<std::__ndk1::unique_ptr<Babylon::ProgramData, std::__ndk1::default_delete<Babylon::ProgramData> >, std::exception_ptr> (arcana::internal::base_task_payload*), 80ul, 16ul, false>::operator()(arcana::internal::base_task_payload*) const+68) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #25 pc 000000000090333c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (arcana::internal::task_payload_with_work<std::__ndk1::unique_ptr<Babylon::ProgramData, std::__ndk1::default_delete<Babylon::ProgramData> >, std::exception_ptr, 80ul>::do_work(arcana::internal::base_task_payload&, arcana::internal::base_task_payload*)+60) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #26 pc 00000000007d452c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (arcana::internal::base_task_payload::run(arcana::internal::base_task_payload*)+60) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #27 pc 0000000000904eac /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #28 pc 0000000000904e80 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #29 pc 0000000000904e34 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #30 pc 0000000000904e10 /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17311-17311 DEBUG pid-17311 A #31 pc 0000000000904b9c /data/app/~~ftEiHebncW2qNxfgZGA4xA==/com.example.myapplication2-VzbKTStKMEzOFlc___gIUQ==/base.apk!libBabylonNativeJNI.so (offset 0x314c000) (BuildId: 75bbd9b58b1f909b72a3722defeabca3f81d1fc2)
2024-10-03 16:30:45.413 17230-17230 BabylonView com.example.myapplication2 D Drawing frame
2024-10-03 16:30:45.430 17230-17230 BabylonView com.example.myapplication2 D Drawing frame
---------------------------- PROCESS ENDED (17230) for package com.example.myapplication2 ----------------------------
It looks like glslang has difficulties to parse the shader. Is it the default grey cube scene?
grey cube scene is not building up , that purple background builds for a second , then it crashes with the above logs
Looks like a ndk/c++ lib mismatch maybe. Is the stdlibc++ statically linked?
cc @bghgary