fix build
This commit is contained in:
@@ -16,38 +16,61 @@ public class BuildScript
|
|||||||
return scenes;
|
return scenes;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("Build/Build Android APK")]
|
[MenuItem("Build/Build Android APK (Direct)")]
|
||||||
public static void BuildAndroid()
|
public static void BuildAndroid()
|
||||||
{
|
{
|
||||||
string outputPath = GetOutputPath();
|
string outputPath = GetOutputPath();
|
||||||
BuildAndroidTo(outputPath);
|
BuildAndroidTo(outputPath, exportProject: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MenuItem("Build/Export Android Project")]
|
||||||
|
public static void ExportAndroid()
|
||||||
|
{
|
||||||
|
string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "Builds", "Android", "MosisVR");
|
||||||
|
BuildAndroidTo(outputPath, exportProject: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void BuildAndroidCI()
|
public static void BuildAndroidCI()
|
||||||
{
|
{
|
||||||
// Called from command line
|
// Called from command line - check for export flag
|
||||||
|
bool exportOnly = GetCommandLineArg("-export") == "true";
|
||||||
|
string outputPath = GetCommandLineArg("-outputPath");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(outputPath))
|
||||||
|
{
|
||||||
|
outputPath = exportOnly
|
||||||
|
? Path.Combine(Directory.GetCurrentDirectory(), "Builds", "Android", "MosisVR")
|
||||||
|
: Path.Combine(Directory.GetCurrentDirectory(), "Builds", "Android", "MosisVR.apk");
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildAndroidTo(outputPath, exportOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void BuildAndroidDirectCI()
|
||||||
|
{
|
||||||
|
// Called from command line - direct APK build (no export)
|
||||||
string outputPath = GetCommandLineArg("-outputPath");
|
string outputPath = GetCommandLineArg("-outputPath");
|
||||||
if (string.IsNullOrEmpty(outputPath))
|
if (string.IsNullOrEmpty(outputPath))
|
||||||
{
|
{
|
||||||
outputPath = Path.Combine(Directory.GetCurrentDirectory(), "Builds", "Android", "MosisVR.apk");
|
outputPath = Path.Combine(Directory.GetCurrentDirectory(), "Builds", "Android", "MosisVR.apk");
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildAndroidTo(outputPath);
|
BuildAndroidTo(outputPath, exportProject: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BuildAndroidTo(string outputPath)
|
private static void BuildAndroidTo(string outputPath, bool exportProject = true)
|
||||||
{
|
{
|
||||||
// Ensure output directory exists
|
// Ensure output directory exists
|
||||||
string outputDir = Path.GetDirectoryName(outputPath);
|
string outputDir = exportProject ? outputPath : Path.GetDirectoryName(outputPath);
|
||||||
if (!Directory.Exists(outputDir))
|
if (!Directory.Exists(outputDir))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(outputDir);
|
Directory.CreateDirectory(outputDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log($"Building Android APK to: {outputPath}");
|
Debug.Log($"Building Android {(exportProject ? "project" : "APK")} to: {outputPath}");
|
||||||
|
|
||||||
// Configure Android settings - export as Gradle project for manual build
|
// Configure Android settings
|
||||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = exportProject;
|
||||||
EditorUserBuildSettings.buildAppBundle = false;
|
EditorUserBuildSettings.buildAppBundle = false;
|
||||||
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
|
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
|
||||||
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARM64;
|
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARM64;
|
||||||
|
|||||||
2
Assets/Plugins/Android/mainTemplate.gradle
generated
2
Assets/Plugins/Android/mainTemplate.gradle
generated
@@ -40,7 +40,7 @@ android {
|
|||||||
defaultConfig.externalNativeBuild{
|
defaultConfig.externalNativeBuild{
|
||||||
cmake {
|
cmake {
|
||||||
arguments += '-DUNITY_PROJECT_DIR="**DIR_UNITYPROJECT**"'
|
arguments += '-DUNITY_PROJECT_DIR="**DIR_UNITYPROJECT**"'
|
||||||
arguments += '-DANDROID_SDK="' + getSdkDir() + '"'
|
arguments += '-DANDROID_SDK="' + System.getenv("ANDROID_HOME") + '"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,24 +48,39 @@ Packages/com.omarator.mosissdk/
|
|||||||
|
|
||||||
## Build Commands
|
## Build Commands
|
||||||
|
|
||||||
### Unity Build (Export to Android Studio)
|
### Option 1: Direct APK Build (Recommended)
|
||||||
|
|
||||||
Unity exports a Gradle project which is then built in Android Studio:
|
Build directly to APK without exporting:
|
||||||
|
|
||||||
1. File > Build Settings
|
```batch
|
||||||
2. Switch Platform to Android
|
"C:\Program Files\Unity\Hub\Editor\6000.3.2f1\Editor\Unity.exe" ^
|
||||||
3. Player Settings > Other Settings:
|
-batchmode -quit -nographics ^
|
||||||
- Scripting Backend: IL2CPP
|
-projectPath "D:\Dev\Mosis\MosisVR" ^
|
||||||
- Target Architectures: ARM64
|
-executeMethod BuildScript.BuildAndroidDirectCI ^
|
||||||
- Graphics APIs: Vulkan, OpenGLES3 (in order of preference)
|
-outputPath "D:\Dev\Mosis\Builds\Unity\Android\MosisVR.apk" ^
|
||||||
- Minimum API Level: 29
|
-logFile "D:\Dev\Mosis\Builds\Unity\build.log"
|
||||||
4. Check "Export Project"
|
```
|
||||||
5. Click Export and select output folder (e.g., `D:\Dev\Mosis\Builds\Unity\Android\MosisVR`)
|
|
||||||
|
|
||||||
### Build Gradle Project
|
Or from Unity Editor: **Build > Build Android APK (Direct)**
|
||||||
|
|
||||||
After exporting from Unity:
|
### Option 2: Export + Gradle Build
|
||||||
|
|
||||||
|
Export a Gradle project for more control over the build process:
|
||||||
|
|
||||||
|
**Step 1: Export from Unity**
|
||||||
|
```batch
|
||||||
|
"C:\Program Files\Unity\Hub\Editor\6000.3.2f1\Editor\Unity.exe" ^
|
||||||
|
-batchmode -quit -nographics ^
|
||||||
|
-projectPath "D:\Dev\Mosis\MosisVR" ^
|
||||||
|
-executeMethod BuildScript.BuildAndroidCI ^
|
||||||
|
-export true ^
|
||||||
|
-outputPath "D:\Dev\Mosis\Builds\Unity\Android\MosisVR" ^
|
||||||
|
-logFile "D:\Dev\Mosis\Builds\Unity\build.log"
|
||||||
|
```
|
||||||
|
|
||||||
|
Or from Unity Editor: **Build > Export Android Project**
|
||||||
|
|
||||||
|
**Step 2: Build with Gradle**
|
||||||
```batch
|
```batch
|
||||||
cd D:\Dev\Mosis\Builds\Unity\Android\MosisVR
|
cd D:\Dev\Mosis\Builds\Unity\Android\MosisVR
|
||||||
gradle assembleRelease
|
gradle assembleRelease
|
||||||
@@ -76,20 +91,21 @@ gradle assembleRelease
|
|||||||
|
|
||||||
Or open in Android Studio and build from there.
|
Or open in Android Studio and build from there.
|
||||||
|
|
||||||
### Command Line Export (Optional)
|
### Unity Editor Manual Build
|
||||||
|
|
||||||
```batch
|
1. File > Build Settings
|
||||||
"C:\Program Files\Unity\Hub\Editor\6000.3.2f1\Editor\Unity.exe" ^
|
2. Switch Platform to Android
|
||||||
-batchmode -quit -nographics ^
|
3. Player Settings > Other Settings:
|
||||||
-projectPath "D:\Dev\Mosis\MosisVR" ^
|
- Scripting Backend: IL2CPP
|
||||||
-executeMethod BuildScript.BuildAndroidCI ^
|
- Target Architectures: ARM64
|
||||||
-outputPath "D:\Dev\Mosis\Builds\Unity\Android\MosisVR" ^
|
- Graphics APIs: Vulkan, OpenGLES3 (in order of preference)
|
||||||
-logFile "D:\Dev\Mosis\Builds\Unity\build.log"
|
- Minimum API Level: 29
|
||||||
```
|
4. For direct APK: Uncheck "Export Project", click Build
|
||||||
|
5. For export: Check "Export Project", click Export
|
||||||
|
|
||||||
### Native Plugin Build (Manual)
|
### Native Plugin Build (Manual)
|
||||||
|
|
||||||
To rebuild the native library manually:
|
The native plugin is built automatically during Unity's build process via CMake. To rebuild manually:
|
||||||
|
|
||||||
```batch
|
```batch
|
||||||
cd Packages/com.omarator.mosissdk/Plugins/Android/cpp
|
cd Packages/com.omarator.mosissdk/Plugins/Android/cpp
|
||||||
@@ -166,10 +182,11 @@ The native plugin automatically selects the appropriate backend:
|
|||||||
|--------------|---------|--------|
|
|--------------|---------|--------|
|
||||||
| Vulkan | VulkanTextureBackend | Preferred |
|
| Vulkan | VulkanTextureBackend | Preferred |
|
||||||
| OpenGL ES 3.0 | OpenGLTextureBackend | Fallback |
|
| OpenGL ES 3.0 | OpenGLTextureBackend | Fallback |
|
||||||
| OpenGL ES 2.0 | OpenGLTextureBackend | Fallback |
|
|
||||||
|
|
||||||
Backend selection happens in `UnityPluginLoad()` based on the active renderer.
|
Backend selection happens in `UnityPluginLoad()` based on the active renderer.
|
||||||
|
|
||||||
|
Note: Unity 6 requires OpenGL ES 3.0 minimum. OpenGL ES 2.0 is not supported.
|
||||||
|
|
||||||
### Vulkan Import
|
### Vulkan Import
|
||||||
|
|
||||||
When using Vulkan, the plugin imports AHardwareBuffer directly as a VkImage:
|
When using Vulkan, the plugin imports AHardwareBuffer directly as a VkImage:
|
||||||
@@ -226,6 +243,28 @@ adb logcat -s Unity MosisSDK Vulkan
|
|||||||
- Check XR input device selection matches controller
|
- Check XR input device selection matches controller
|
||||||
- Test with mouse click fallback in editor
|
- Test with mouse click fallback in editor
|
||||||
|
|
||||||
|
### Build Fails with "glad/gles2.h not found"
|
||||||
|
|
||||||
|
This error occurs when IL2CPP tries to compile native plugin C++ files. The `.meta` files for the cpp/h files must have `PluginImporter` settings with `enabled: 0` for all platforms to exclude them from IL2CPP.
|
||||||
|
|
||||||
|
**Solution**: Ensure all `.meta` files in `Plugins/Android/cpp/` have proper PluginImporter exclusion settings:
|
||||||
|
```yaml
|
||||||
|
PluginImporter:
|
||||||
|
platformData:
|
||||||
|
Android:
|
||||||
|
enabled: 0
|
||||||
|
Any:
|
||||||
|
enabled: 0
|
||||||
|
settings:
|
||||||
|
Exclude Android: 1
|
||||||
|
Exclude Editor: 1
|
||||||
|
# ... exclude all platforms
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build Fails with "getSdkDir() not found"
|
||||||
|
|
||||||
|
The `mainTemplate.gradle` must use `System.getenv("ANDROID_HOME")` instead of `getSdkDir()` for the ANDROID_SDK cmake argument. Ensure `ANDROID_HOME` environment variable is set.
|
||||||
|
|
||||||
## Implementation Notes
|
## Implementation Notes
|
||||||
|
|
||||||
### Files Modified in Vulkan Implementation
|
### Files Modified in Vulkan Implementation
|
||||||
@@ -249,3 +288,4 @@ adb logcat -s Unity MosisSDK Vulkan
|
|||||||
|
|
||||||
- **1.0.0** - Initial release with OpenGL support
|
- **1.0.0** - Initial release with OpenGL support
|
||||||
- **1.1.0** - Added Vulkan backend, touch down/up events, dynamic resolution
|
- **1.1.0** - Added Vulkan backend, touch down/up events, dynamic resolution
|
||||||
|
- **1.2.0** - Fixed IL2CPP build compatibility, added direct APK build support, fixed mainTemplate.gradle for direct builds
|
||||||
|
|||||||
Reference in New Issue
Block a user