浏览代码

Android fixes

Panagiotis Christopoulos Charitos 4 年之前
父节点
当前提交
a3a4151f2e

+ 10 - 1
AnKi/Config.h.cmake

@@ -207,10 +207,19 @@
 
 
 // Define the main() function.
 // Define the main() function.
 #if ANKI_OS_ANDROID
 #if ANKI_OS_ANDROID
+extern "C" {
+	struct android_app;
+}
+
+namespace anki {
+	extern android_app* g_androidApp;
+}
+
 #	define ANKI_MAIN_FUNCTION(myMain) \
 #	define ANKI_MAIN_FUNCTION(myMain) \
 	int myMain(int argc, char* argv[]); \
 	int myMain(int argc, char* argv[]); \
-	void android_main(struct android_app* app) \
+	extern "C" void android_main(android_app* app) \
 	{ \
 	{ \
+		anki::g_androidApp = app; \
 		char* argv[] = {"androidapp"}; \
 		char* argv[] = {"androidapp"}; \
 		myMain(1, argv); \
 		myMain(1, argv); \
 	}
 	}

+ 1 - 1
AnKi/Core/App.cpp

@@ -511,7 +511,7 @@ Error App::initDirs(const ConfigSet& cfg)
 
 
 	m_settingsDir.sprintf(m_heapAlloc, "%s/.anki", &home[0]);
 	m_settingsDir.sprintf(m_heapAlloc, "%s/.anki", &home[0]);
 #else
 #else
-	m_settingsDir.sprintf(m_heapAlloc, "%s/.anki", "/sdcard");
+	m_settingsDir.sprintf(m_heapAlloc, "%s/.anki", g_androidApp->activity->internalDataPath);
 #endif
 #endif
 
 
 	if(!directoryExists(m_settingsDir.toCString()))
 	if(!directoryExists(m_settingsDir.toCString()))

+ 0 - 7
AnKi/Core/App.h

@@ -10,17 +10,10 @@
 #include <AnKi/Util/String.h>
 #include <AnKi/Util/String.h>
 #include <AnKi/Util/Ptr.h>
 #include <AnKi/Util/Ptr.h>
 #include <AnKi/Ui/UiImmediateModeBuilder.h>
 #include <AnKi/Ui/UiImmediateModeBuilder.h>
-#if ANKI_OS_ANDROID
-#	include <android_native_app_glue.h>
-#endif
 
 
 namespace anki
 namespace anki
 {
 {
 
 
-#if ANKI_OS_ANDROID
-extern android_app* gAndroidApp;
-#endif
-
 // Forward
 // Forward
 class CoreTracer;
 class CoreTracer;
 class ConfigSet;
 class ConfigSet;

+ 5 - 1
AnKi/Core/NativeWindowAndroid.cpp

@@ -12,10 +12,10 @@ Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
 {
 {
 	ANKI_CORE_LOGI("Initializing Android window");
 	ANKI_CORE_LOGI("Initializing Android window");
 
 
+	m_alloc = alloc;
 	m_impl = m_alloc.newInstance<NativeWindowImpl>();
 	m_impl = m_alloc.newInstance<NativeWindowImpl>();
 
 
 	// Loop until the window is ready
 	// Loop until the window is ready
-	extern android_app* g_androidApp;
 	while(g_androidApp->window == nullptr)
 	while(g_androidApp->window == nullptr)
 	{
 	{
 		int ident;
 		int ident;
@@ -34,6 +34,10 @@ Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
 
 
 	m_impl->m_nativeWindow = g_androidApp->window;
 	m_impl->m_nativeWindow = g_androidApp->window;
 
 
+	// Set some stuff
+	m_width = ANativeWindow_getWidth(g_androidApp->window);
+	m_height = ANativeWindow_getHeight(g_androidApp->window);
+
 	return Error::NONE;
 	return Error::NONE;
 }
 }
 
 

+ 0 - 2
AnKi/Util/File.cpp

@@ -18,8 +18,6 @@ namespace anki
 {
 {
 
 
 #if ANKI_OS_ANDROID
 #if ANKI_OS_ANDROID
-extern android_app* g_androidApp;
-
 #	define ANKI_AFILE static_cast<AAsset*>(m_file)
 #	define ANKI_AFILE static_cast<AAsset*>(m_file)
 #endif
 #endif
 
 

+ 8 - 4
Samples/Common/Framework.cpp

@@ -10,6 +10,12 @@ using namespace anki;
 Error SampleApp::init(int argc, char** argv, CString sampleName)
 Error SampleApp::init(int argc, char** argv, CString sampleName)
 {
 {
 	HeapAllocator<U32> alloc(allocAligned, nullptr);
 	HeapAllocator<U32> alloc(allocAligned, nullptr);
+
+	// Init the super class
+	ConfigSet config = DefaultConfigSet::get();
+	config.set("window_fullscreen", true);
+
+#if !ANKI_OS_ANDROID
 	StringAuto mainDataPath(alloc, ANKI_SOURCE_DIRECTORY);
 	StringAuto mainDataPath(alloc, ANKI_SOURCE_DIRECTORY);
 	StringAuto assetsDataPath(alloc);
 	StringAuto assetsDataPath(alloc);
 	assetsDataPath.sprintf("%s/Samples/%s", ANKI_SOURCE_DIRECTORY, sampleName.cstr());
 	assetsDataPath.sprintf("%s/Samples/%s", ANKI_SOURCE_DIRECTORY, sampleName.cstr());
@@ -19,11 +25,9 @@ Error SampleApp::init(int argc, char** argv, CString sampleName)
 		ANKI_LOGE("Cannot find directory \"%s\". Have you moved the clone of the repository?", assetsDataPath.cstr());
 		ANKI_LOGE("Cannot find directory \"%s\". Have you moved the clone of the repository?", assetsDataPath.cstr());
 		return Error::USER_DATA;
 		return Error::USER_DATA;
 	}
 	}
-
-	// Init the super class
-	ConfigSet config = DefaultConfigSet::get();
-	config.set("window_fullscreen", true);
 	config.set("rsrc_dataPaths", StringAuto(alloc).sprintf("%s:%s", mainDataPath.cstr(), assetsDataPath.cstr()));
 	config.set("rsrc_dataPaths", StringAuto(alloc).sprintf("%s:%s", mainDataPath.cstr(), assetsDataPath.cstr()));
+#endif
+
 	config.set("gr_validation", 0);
 	config.set("gr_validation", 0);
 	ANKI_CHECK(config.setFromCommandLineArguments(argc - 1, argv + 1));
 	ANKI_CHECK(config.setFromCommandLineArguments(argc - 1, argv + 1));
 	ANKI_CHECK(App::init(config, allocAligned, nullptr));
 	ANKI_CHECK(App::init(config, allocAligned, nullptr));

+ 2 - 0
Samples/Sponza/GenerateAndroidProject.sh

@@ -1,3 +1,5 @@
 #!/bin/bash
 #!/bin/bash
 
 
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
+cd $SCRIPT_DIR
 ../../Tools/Android/GenerateAndroidProject.py -o ../.. -t Sponza -a ./Assets/
 ../../Tools/Android/GenerateAndroidProject.py -o ../.. -t Sponza -a ./Assets/

+ 3 - 0
Tools/Android/GenerateAndroidProject.py

@@ -91,6 +91,9 @@ def main():
     replace_in_file(build_gradle, "%PYTHON%", sys.executable)
     replace_in_file(build_gradle, "%PYTHON%", sys.executable)
     replace_in_file(build_gradle, "%CMAKE%", os.path.join(this_script_dir, "../../CMakeLists.txt"))
     replace_in_file(build_gradle, "%CMAKE%", os.path.join(this_script_dir, "../../CMakeLists.txt"))
 
 
+    # Manifest
+    replace_in_file(os.path.join(project_dir, "app/src/main/AndroidManifest.xml"), "%TARGET%", ctx.target)
+
     # Done
     # Done
     print("Generated project: %s" % project_dir)
     print("Generated project: %s" % project_dir)
 
 

+ 8 - 9
Tools/Android/app/src/main/AndroidManifest.xml

@@ -1,24 +1,23 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<!-- BEGIN_INCLUDE(manifest) -->
+
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-        package="com.google.vulkan.tutorials.five">
+        package="org.anki.%TARGET%">
 
 
     <application android:label="@string/app_name"
     <application android:label="@string/app_name"
         android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
         android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
-
-        <!-- Our activity is the built-in NativeActivity framework class.
-             This will take care of integrating with our NDK code. -->
         <activity android:name="android.app.NativeActivity"
         <activity android:name="android.app.NativeActivity"
+                android:screenOrientation="landscape"
                 android:label="@string/app_name"
                 android:label="@string/app_name"
                 android:configChanges="orientation|keyboardHidden">
                 android:configChanges="orientation|keyboardHidden">
-            <!-- Tell NativeActivity the name of or .so -->
-            <meta-data android:name="android.app.lib_name" android:value="Sponza" />
+            <meta-data android:name="android.app.lib_name" android:value="%TARGET%" />
             <intent-filter>
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
             </intent-filter>
         </activity>
         </activity>
     </application>
     </application>
-
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 </manifest>
 </manifest>
-<!-- END_INCLUDE(manifest) -->