The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1272 lines
55KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class AndroidProjectExporter : public ProjectExporter
  18. {
  19. public:
  20. //==============================================================================
  21. bool isXcode() const override { return false; }
  22. bool isVisualStudio() const override { return false; }
  23. bool isCodeBlocks() const override { return false; }
  24. bool isMakefile() const override { return false; }
  25. bool isAndroidStudio() const override { return true; }
  26. bool isAndroid() const override { return true; }
  27. bool isWindows() const override { return false; }
  28. bool isLinux() const override { return false; }
  29. bool isOSX() const override { return false; }
  30. bool isiOS() const override { return false; }
  31. bool usesMMFiles() const override { return false; }
  32. bool canCopeWithDuplicateFiles() override { return false; }
  33. bool supportsUserDefinedConfigurations() const override { return true; }
  34. bool supportsTargetType (ProjectType::Target::Type type) const override
  35. {
  36. switch (type)
  37. {
  38. case ProjectType::Target::GUIApp:
  39. case ProjectType::Target::StaticLibrary:
  40. case ProjectType::Target::StandalonePlugIn:
  41. return true;
  42. default:
  43. break;
  44. }
  45. return false;
  46. }
  47. //==============================================================================
  48. void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
  49. {
  50. // no-op.
  51. }
  52. //==============================================================================
  53. void createExporterProperties (PropertyListBuilder& props) override
  54. {
  55. createBaseExporterProperties (props);
  56. createToolchainExporterProperties (props);
  57. createManifestExporterProperties (props);
  58. createLibraryModuleExporterProperties (props);
  59. createCodeSigningExporterProperties (props);
  60. createOtherExporterProperties (props);
  61. }
  62. static const char* getName() { return "Android"; }
  63. static const char* getValueTreeTypeName() { return "ANDROIDSTUDIO"; }
  64. static AndroidProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  65. {
  66. if (settings.hasType (getValueTreeTypeName()))
  67. return new AndroidProjectExporter (project, settings);
  68. return nullptr;
  69. }
  70. //==============================================================================
  71. CachedValue<String> androidScreenOrientation, androidActivityClass, androidActivitySubClassName,
  72. androidVersionCode, androidMinimumSDK, androidTheme,
  73. androidSharedLibraries, androidStaticLibraries;
  74. CachedValue<bool> androidInternetNeeded, androidMicNeeded, androidBluetoothNeeded;
  75. CachedValue<String> androidOtherPermissions;
  76. CachedValue<String> androidKeyStore, androidKeyStorePass, androidKeyAlias, androidKeyAliasPass;
  77. CachedValue<String> gradleVersion, androidPluginVersion, gradleToolchain, buildToolsVersion;
  78. //==============================================================================
  79. AndroidProjectExporter (Project& p, const ValueTree& t)
  80. : ProjectExporter (p, t),
  81. androidScreenOrientation (settings, Ids::androidScreenOrientation, nullptr, "unspecified"),
  82. androidActivityClass (settings, Ids::androidActivityClass, nullptr, createDefaultClassName()),
  83. androidActivitySubClassName (settings, Ids::androidActivitySubClassName, nullptr),
  84. androidVersionCode (settings, Ids::androidVersionCode, nullptr, "1"),
  85. androidMinimumSDK (settings, Ids::androidMinimumSDK, nullptr, "10"),
  86. androidTheme (settings, Ids::androidTheme, nullptr),
  87. androidSharedLibraries (settings, Ids::androidSharedLibraries, nullptr, ""),
  88. androidStaticLibraries (settings, Ids::androidStaticLibraries, nullptr, ""),
  89. androidInternetNeeded (settings, Ids::androidInternetNeeded, nullptr, true),
  90. androidMicNeeded (settings, Ids::microphonePermissionNeeded, nullptr, false),
  91. androidBluetoothNeeded (settings, Ids::androidBluetoothNeeded, nullptr, true),
  92. androidOtherPermissions (settings, Ids::androidOtherPermissions, nullptr),
  93. androidKeyStore (settings, Ids::androidKeyStore, nullptr, "${user.home}/.android/debug.keystore"),
  94. androidKeyStorePass (settings, Ids::androidKeyStorePass, nullptr, "android"),
  95. androidKeyAlias (settings, Ids::androidKeyAlias, nullptr, "androiddebugkey"),
  96. androidKeyAliasPass (settings, Ids::androidKeyAliasPass, nullptr, "android"),
  97. gradleVersion (settings, Ids::gradleVersion, nullptr, "2.14.1"),
  98. androidPluginVersion (settings, Ids::androidPluginVersion, nullptr, "2.2.3"),
  99. gradleToolchain (settings, Ids::gradleToolchain, nullptr, "clang"),
  100. buildToolsVersion (settings, Ids::buildToolsVersion, nullptr, "25.0.2"),
  101. AndroidExecutable (findAndroidExecutable())
  102. {
  103. initialiseDependencyPathValues();
  104. name = getName();
  105. if (getTargetLocationString().isEmpty())
  106. getTargetLocationValue() = getDefaultBuildsRootFolder() + "Android";
  107. }
  108. //==============================================================================
  109. void createToolchainExporterProperties (PropertyListBuilder& props)
  110. {
  111. props.add (new TextWithDefaultPropertyComponent<String> (gradleVersion, "gradle version", 32),
  112. "The version of gradle that is used to build this app (2.14.1 is fine for JUCE)");
  113. props.add (new TextWithDefaultPropertyComponent<String> (androidPluginVersion, "android plug-in version", 32),
  114. "The version of the android build plugin for gradle that is used to build this app");
  115. static const char* toolchains[] = { "clang", "gcc", nullptr };
  116. props.add (new ChoicePropertyComponent (gradleToolchain.getPropertyAsValue(), "NDK Toolchain", StringArray (toolchains), Array<var> (toolchains)),
  117. "The toolchain that gradle should invoke for NDK compilation (variable model.android.ndk.tooclhain in app/build.gradle)");
  118. props.add (new TextWithDefaultPropertyComponent<String> (buildToolsVersion, "Android build tools version", 32),
  119. "The Android build tools version that should use to build this app");
  120. }
  121. void createLibraryModuleExporterProperties (PropertyListBuilder& props)
  122. {
  123. props.add (new TextPropertyComponent (androidStaticLibraries.getPropertyAsValue(), "Import static library modules", 8192, true),
  124. "Comma or whitespace delimited list of static libraries (.a) defined in NDK_MODULE_PATH.");
  125. props.add (new TextPropertyComponent (androidSharedLibraries.getPropertyAsValue(), "Import shared library modules", 8192, true),
  126. "Comma or whitespace delimited list of shared libraries (.so) defined in NDK_MODULE_PATH.");
  127. }
  128. //==============================================================================
  129. bool canLaunchProject() override
  130. {
  131. return AndroidExecutable.exists();
  132. }
  133. bool launchProject() override
  134. {
  135. if (! AndroidExecutable.exists())
  136. {
  137. jassertfalse;
  138. return false;
  139. }
  140. const File targetFolder (getTargetFolder());
  141. // we have to surround the path with extra quotes, otherwise Android Studio
  142. // will choke if there are any space characters in the path.
  143. return AndroidExecutable.startAsProcess ("\"" + targetFolder.getFullPathName() + "\"");
  144. }
  145. //==============================================================================
  146. void create (const OwnedArray<LibraryModule>& modules) const override
  147. {
  148. const File targetFolder (getTargetFolder());
  149. const File appFolder (targetFolder.getChildFile (isLibrary() ? "lib" : "app"));
  150. removeOldFiles (targetFolder);
  151. {
  152. const String package (getActivityClassPackage());
  153. const String path (package.replaceCharacter ('.', File::separator));
  154. const File javaTarget (targetFolder.getChildFile ("app/src/main/java").getChildFile (path));
  155. if (! isLibrary())
  156. copyActivityJavaFiles (modules, javaTarget, package);
  157. }
  158. writeFile (targetFolder, "settings.gradle", isLibrary() ? "include ':lib'" : "include ':app'");
  159. writeFile (targetFolder, "build.gradle", getProjectBuildGradleFileContent());
  160. writeFile (appFolder, "build.gradle", getAppBuildGradleFileContent());
  161. writeFile (targetFolder, "local.properties", getLocalPropertiesFileContent());
  162. writeFile (targetFolder, "gradle/wrapper/gradle-wrapper.properties", getGradleWrapperPropertiesFileContent());
  163. writeBinaryFile (targetFolder, "gradle/wrapper/LICENSE-for-gradlewrapper.txt", BinaryData::LICENSE, BinaryData::LICENSESize);
  164. writeBinaryFile (targetFolder, "gradle/wrapper/gradle-wrapper.jar", BinaryData::gradlewrapper_jar, BinaryData::gradlewrapper_jarSize);
  165. writeBinaryFile (targetFolder, "gradlew", BinaryData::gradlew, BinaryData::gradlewSize);
  166. writeBinaryFile (targetFolder, "gradlew.bat", BinaryData::gradlew_bat, BinaryData::gradlew_batSize);
  167. targetFolder.getChildFile ("gradlew").setExecutePermission (true);
  168. writeAndroidManifest (appFolder);
  169. if (! isLibrary())
  170. {
  171. writeStringsXML (targetFolder);
  172. writeAppIcons (targetFolder);
  173. }
  174. writeCmakeFile (appFolder.getChildFile ("CMakeLists.txt"));
  175. }
  176. void removeOldFiles (const File& targetFolder) const
  177. {
  178. targetFolder.getChildFile ("app/src").deleteRecursively();
  179. targetFolder.getChildFile ("app/build").deleteRecursively();
  180. targetFolder.getChildFile ("app/build.gradle").deleteFile();
  181. targetFolder.getChildFile ("gradle").deleteRecursively();
  182. targetFolder.getChildFile ("local.properties").deleteFile();
  183. targetFolder.getChildFile ("settings.gradle").deleteFile();
  184. }
  185. void writeFile (const File& gradleProjectFolder, const String& filePath, const String& fileContent) const
  186. {
  187. MemoryOutputStream outStream;
  188. outStream << fileContent;
  189. overwriteFileIfDifferentOrThrow (gradleProjectFolder.getChildFile (filePath), outStream);
  190. }
  191. void writeBinaryFile (const File& gradleProjectFolder, const String& filePath, const char* binaryData, const int binarySize) const
  192. {
  193. MemoryOutputStream outStream;
  194. outStream.write (binaryData, static_cast<size_t> (binarySize));
  195. overwriteFileIfDifferentOrThrow (gradleProjectFolder.getChildFile (filePath), outStream);
  196. }
  197. //==============================================================================
  198. static File findAndroidExecutable()
  199. {
  200. #if JUCE_WINDOWS
  201. const File defaultInstallation ("C:\\Program Files\\Android\\Android Studio\\bin");
  202. if (defaultInstallation.exists())
  203. {
  204. {
  205. const File studio64 = defaultInstallation.getChildFile ("studio64.exe");
  206. if (studio64.existsAsFile())
  207. return studio64;
  208. }
  209. {
  210. const File studio = defaultInstallation.getChildFile ("studio.exe");
  211. if (studio.existsAsFile())
  212. return studio;
  213. }
  214. }
  215. #elif JUCE_MAC
  216. const File defaultInstallation ("/Applications/Android Studio.app");
  217. if (defaultInstallation.exists())
  218. return defaultInstallation;
  219. #endif
  220. return File();
  221. }
  222. protected:
  223. //==============================================================================
  224. class AndroidBuildConfiguration : public BuildConfiguration
  225. {
  226. public:
  227. AndroidBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  228. : BuildConfiguration (p, settings, e)
  229. {
  230. if (getArchitectures().isEmpty())
  231. {
  232. if (isDebug())
  233. getArchitecturesValue() = "armeabi x86";
  234. else
  235. getArchitecturesValue() = "";
  236. }
  237. }
  238. Value getArchitecturesValue() { return getValue (Ids::androidArchitectures); }
  239. String getArchitectures() const { return config [Ids::androidArchitectures]; }
  240. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? gccO0 : gccO3)); }
  241. void createConfigProperties (PropertyListBuilder& props) override
  242. {
  243. addGCCOptimisationProperty (props);
  244. props.add (new TextPropertyComponent (getArchitecturesValue(), "Architectures", 256, false),
  245. "A list of the ARM architectures to build (for a fat binary). Leave empty to build for all possible android archiftectures.");
  246. }
  247. String getProductFlavourNameIdentifier() const
  248. {
  249. return getName().toLowerCase().replaceCharacter (L' ', L'_') + String ("_");
  250. }
  251. String getProductFlavourCMakeIdentifier() const
  252. {
  253. return getName().toUpperCase().replaceCharacter (L' ', L'_');
  254. }
  255. };
  256. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  257. {
  258. return new AndroidBuildConfiguration (project, v, *this);
  259. }
  260. private:
  261. void writeCmakeFile (const File& file) const
  262. {
  263. MemoryOutputStream mo;
  264. mo << "# Automatically generated makefile, created by the Projucer" << newLine
  265. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  266. << newLine;
  267. mo << "cmake_minimum_required(VERSION 3.4.1)" << newLine << newLine;
  268. if (! isLibrary())
  269. mo << "SET(BINARY_NAME \"juce_jni\")" << newLine << newLine;
  270. {
  271. StringArray projectDefines (getEscapedPreprocessorDefs (getProjectPreprocessorDefs()));
  272. if (projectDefines.size() > 0)
  273. mo << "add_definitions(" << projectDefines.joinIntoString (" ") << ")" << newLine << newLine;
  274. }
  275. writeCmakePathLines (mo, "", "include_directories( AFTER", extraSearchPaths);
  276. const String& cfgExtraLinkerFlags = getExtraLinkerFlagsString();
  277. if (cfgExtraLinkerFlags.isNotEmpty())
  278. {
  279. mo << "SET( JUCE_LDFLAGS \"" << cfgExtraLinkerFlags.replace ("\"", "\\\"") << "\")" << newLine;
  280. mo << "SET( CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} ${JUCE_LDFLAGS}\")" << newLine << newLine;
  281. }
  282. if (getNumConfigurations() > 0)
  283. {
  284. bool first = true;
  285. for (ConstConfigIterator config (*this); config.next();)
  286. {
  287. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  288. const StringArray& libSearchPaths = cfg.getLibrarySearchPaths();
  289. const StringPairArray& cfgDefines = getConfigPreprocessorDefs (cfg);
  290. const StringArray& cfgHeaderPaths = cfg.getHeaderSearchPaths();
  291. const StringArray& cfgLibraryPaths = cfg.getLibrarySearchPaths();
  292. if (! isLibrary() && libSearchPaths.size() == 0 && cfgDefines.size() == 0
  293. && cfgHeaderPaths.size() == 0 && cfgLibraryPaths.size() == 0)
  294. continue;
  295. mo << (first ? "IF" : "ELSEIF") << "(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg.getProductFlavourCMakeIdentifier() <<"\")" << newLine;
  296. if (isLibrary())
  297. mo << " SET(BINARY_NAME \"" << getNativeModuleBinaryName (cfg) << "\")" << newLine;
  298. writeCmakePathLines (mo, " ", "link_directories(", libSearchPaths);
  299. if (cfgDefines.size() > 0)
  300. mo << " add_definitions(" << getEscapedPreprocessorDefs (cfgDefines).joinIntoString (" ") << ")" << newLine;
  301. writeCmakePathLines (mo, " ", "include_directories( AFTER", cfgHeaderPaths);
  302. writeCmakePathLines (mo, " ", "link_directories(", cfgLibraryPaths);
  303. first = false;
  304. }
  305. if (! first)
  306. {
  307. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (* getConfiguration(0));
  308. mo << "ELSE(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg.getProductFlavourCMakeIdentifier() <<"\")" << newLine;
  309. mo << " MESSAGE( FATAL_ERROR \"No matching build-configuration found.\" )" << newLine;
  310. mo << "ENDIF(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg.getProductFlavourCMakeIdentifier() <<"\")" << newLine << newLine;
  311. }
  312. }
  313. Array<RelativePath> excludeFromBuild;
  314. mo << "add_library( ${BINARY_NAME}" << newLine;
  315. mo << newLine;
  316. mo << " SHARED" << newLine;
  317. mo << newLine;
  318. addCompileUnits (mo, excludeFromBuild);
  319. mo << ")" << newLine << newLine;
  320. if (excludeFromBuild.size() > 0)
  321. {
  322. for (auto& exclude : excludeFromBuild)
  323. mo << "set_source_files_properties(\"" << exclude.toUnixStyle() << "\" PROPERTIES HEADER_FILE_ONLY TRUE)" << newLine;
  324. mo << newLine;
  325. }
  326. const StringArray& libraries = getProjectLibraries();
  327. if (libraries.size() > 0)
  328. {
  329. for (auto& lib : libraries)
  330. mo << "find_library(" << lib.toLowerCase().replaceCharacter (L' ', L'_') << " \"" << lib << "\")" << newLine;
  331. mo << newLine;
  332. }
  333. mo << "target_link_libraries( ${BINARY_NAME}";
  334. if (libraries.size() > 0)
  335. {
  336. mo << newLine << newLine;
  337. for (auto& lib : libraries)
  338. mo << " ${" << lib.toLowerCase().replaceCharacter (L' ', L'_') << "}" << newLine;
  339. }
  340. mo << ")" << newLine;
  341. overwriteFileIfDifferentOrThrow (file, mo);
  342. }
  343. //==============================================================================
  344. String getProjectBuildGradleFileContent() const
  345. {
  346. MemoryOutputStream mo;
  347. mo << "buildscript {" << newLine;
  348. mo << " repositories {" << newLine;
  349. mo << " jcenter()" << newLine;
  350. mo << " }" << newLine;
  351. mo << " dependencies {" << newLine;
  352. mo << " classpath 'com.android.tools.build:gradle:" << androidPluginVersion.get() << "'" << newLine;
  353. mo << " }" << newLine;
  354. mo << "}" << newLine;
  355. mo << "" << newLine;
  356. mo << "allprojects {" << newLine;
  357. mo << " repositories {" << newLine;
  358. mo << " jcenter()" << newLine;
  359. mo << " }" << newLine;
  360. mo << "}" << newLine;
  361. return mo.toString();
  362. }
  363. //==============================================================================
  364. String getAppBuildGradleFileContent () const
  365. {
  366. MemoryOutputStream mo;
  367. mo << "apply plugin: 'com.android." << (isLibrary() ? "library" : "application") << "'" << newLine << newLine;
  368. mo << "android {" << newLine;
  369. mo << " compileSdkVersion " << androidMinimumSDK.get().getIntValue() << newLine;
  370. mo << " buildToolsVersion \"" << buildToolsVersion.get() << "\"" << newLine;
  371. mo << " externalNativeBuild {" << newLine;
  372. mo << " cmake {" << newLine;
  373. mo << " path \"CMakeLists.txt\"" << newLine;
  374. mo << " }" << newLine;
  375. mo << " }" << newLine;
  376. mo << getAndroidSigningConfig() << newLine;
  377. mo << getAndroidDefaultConfig() << newLine;
  378. mo << getAndroidBuildTypes() << newLine;
  379. mo << getAndroidProductFlavours() << newLine;
  380. mo << getAndroidVariantFilter() << newLine;
  381. mo << "}" << newLine;
  382. return mo.toString();
  383. }
  384. String getAndroidProductFlavours() const
  385. {
  386. MemoryOutputStream mo;
  387. mo << " productFlavors {" << newLine;
  388. for (ConstConfigIterator config (*this); config.next();)
  389. {
  390. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  391. mo << " " << cfg.getProductFlavourNameIdentifier() << " {" << newLine;
  392. if (cfg.getArchitectures().isNotEmpty())
  393. {
  394. mo << " ndk {" << newLine;
  395. mo << " abiFilters " << toGradleList (StringArray::fromTokens (cfg.getArchitectures(), " ", "")) << newLine;
  396. mo << " }" << newLine;
  397. }
  398. mo << " externalNativeBuild {" << newLine;
  399. mo << " cmake {" << newLine;
  400. mo << " arguments \"-DJUCE_BUILD_CONFIGFURATION=" << cfg.getProductFlavourCMakeIdentifier() << "\"" << newLine;
  401. mo << " cFlags \"-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
  402. mo << " cppFlags \"-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
  403. mo << " }" << newLine;
  404. mo << " }" << newLine;
  405. mo << " }" << newLine;
  406. }
  407. mo << " }" << newLine;
  408. return mo.toString();
  409. }
  410. String getAndroidSigningConfig() const
  411. {
  412. MemoryOutputStream mo;
  413. String keyStoreFilePath = androidKeyStore.get().replace ("${user.home}", "${System.properties['user.home']}")
  414. .replace ("/", "${File.separator}");
  415. mo << " signingConfigs {" << newLine;
  416. mo << " release {" << newLine;
  417. mo << " storeFile file(\"" << keyStoreFilePath << "\")" << newLine;
  418. mo << " storePassword \"" << androidKeyStorePass.get() << "\"" << newLine;
  419. mo << " keyAlias \"" << androidKeyAlias.get() << "\"" << newLine;
  420. mo << " keyPassword \"" << androidKeyAliasPass.get() << "\"" << newLine;
  421. mo << " storeType \"jks\"" << newLine;
  422. mo << " }" << newLine;
  423. mo << " }" << newLine;
  424. return mo.toString();
  425. }
  426. String getAndroidDefaultConfig() const
  427. {
  428. const String bundleIdentifier = project.getBundleIdentifier().toString().toLowerCase();
  429. const StringArray& cmakeDefs = getCmakeDefinitions();
  430. const StringArray& cFlags = getProjectCompilerFlags();
  431. const StringArray& cxxFlags = getProjectCxxCompilerFlags();
  432. const int minSdkVersion = androidMinimumSDK.get().getIntValue();
  433. MemoryOutputStream mo;
  434. mo << " defaultConfig {" << newLine;
  435. if (! isLibrary())
  436. mo << " applicationId \"" << bundleIdentifier << "\"" << newLine;
  437. mo << " minSdkVersion " << minSdkVersion << newLine;
  438. mo << " targetSdkVersion " << minSdkVersion << newLine;
  439. mo << " externalNativeBuild {" << newLine;
  440. mo << " cmake {" << newLine;
  441. mo << " arguments " << cmakeDefs.joinIntoString (", ") << newLine;
  442. if (cFlags.size() > 0)
  443. mo << " cFlags " << cFlags.joinIntoString (", ") << newLine;
  444. if (cxxFlags.size() > 0)
  445. mo << " cppFlags " << cxxFlags.joinIntoString (", ") << newLine;
  446. mo << " }" << newLine;
  447. mo << " }" << newLine;
  448. mo << " }" << newLine;
  449. return mo.toString();
  450. }
  451. String getAndroidBuildTypes() const
  452. {
  453. MemoryOutputStream mo;
  454. mo << " buildTypes {" << newLine;
  455. int numDebugConfigs = 0;
  456. const int numConfigs = getNumConfigurations();
  457. for (int i = 0; i < numConfigs; ++i)
  458. {
  459. auto config = getConfiguration(i);
  460. if (config->isDebug()) numDebugConfigs++;
  461. if (numDebugConfigs > 1 || ((numConfigs - numDebugConfigs) > 1))
  462. continue;
  463. mo << " " << (config->isDebug() ? "debug" : "release") << " {" << newLine;
  464. mo << " initWith " << (config->isDebug() ? "debug" : "release") << newLine;
  465. mo << " debuggable " << (config->isDebug() ? "true" : "false") << newLine;
  466. mo << " jniDebuggable " << (config->isDebug() ? "true" : "false") << newLine;
  467. if (! config->isDebug())
  468. mo << " signingConfig signingConfigs.release" << newLine;
  469. mo << " }" << newLine;
  470. }
  471. mo << " }" << newLine;
  472. return mo.toString();
  473. }
  474. String getAndroidVariantFilter() const
  475. {
  476. MemoryOutputStream mo;
  477. mo << " variantFilter { variant ->" << newLine;
  478. mo << " def names = variant.flavors*.name" << newLine;
  479. for (ConstConfigIterator config (*this); config.next();)
  480. {
  481. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  482. mo << " if (names.contains (\"" << cfg.getProductFlavourNameIdentifier() << "\")" << newLine;
  483. mo << " && variant.buildType.name != \"" << (cfg.isDebug() ? "debug" : "release") << "\") {" << newLine;
  484. mo << " setIgnore(true)" << newLine;
  485. mo << " }" << newLine;
  486. }
  487. mo << " }" << newLine;
  488. return mo.toString();
  489. }
  490. //==============================================================================
  491. String getLocalPropertiesFileContent() const
  492. {
  493. String props;
  494. props << "ndk.dir=" << sanitisePath (ndkPath.toString()) << newLine
  495. << "sdk.dir=" << sanitisePath (sdkPath.toString()) << newLine;
  496. return props;
  497. }
  498. String getGradleWrapperPropertiesFileContent() const
  499. {
  500. String props;
  501. props << "distributionUrl=https\\://services.gradle.org/distributions/gradle-"
  502. << gradleVersion.get() << "-all.zip";
  503. return props;
  504. }
  505. //==============================================================================
  506. void createBaseExporterProperties (PropertyListBuilder& props)
  507. {
  508. static const char* orientations[] = { "Portrait and Landscape", "Portrait", "Landscape", nullptr };
  509. static const char* orientationValues[] = { "unspecified", "portrait", "landscape", nullptr };
  510. props.add (new ChoicePropertyComponent (androidScreenOrientation.getPropertyAsValue(), "Screen orientation", StringArray (orientations), Array<var> (orientationValues)),
  511. "The screen orientations that this app should support");
  512. props.add (new TextWithDefaultPropertyComponent<String> (androidActivityClass, "Android Activity class name", 256),
  513. "The full java class name to use for the app's Activity class.");
  514. props.add (new TextPropertyComponent (androidActivitySubClassName.getPropertyAsValue(), "Android Activity sub-class name", 256, false),
  515. "If not empty, specifies the Android Activity class name stored in the app's manifest. "
  516. "Use this if you would like to use your own Android Activity sub-class.");
  517. props.add (new TextWithDefaultPropertyComponent<String> (androidVersionCode, "Android Version Code", 32),
  518. "An integer value that represents the version of the application code, relative to other versions.");
  519. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), sdkPath, "Android SDK Path"),
  520. "The path to the Android SDK folder on the target build machine");
  521. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), ndkPath, "Android NDK Path"),
  522. "The path to the Android NDK folder on the target build machine");
  523. props.add (new TextWithDefaultPropertyComponent<String> (androidMinimumSDK, "Minimum SDK version", 32),
  524. "The number of the minimum version of the Android SDK that the app requires");
  525. }
  526. //==============================================================================
  527. void createManifestExporterProperties (PropertyListBuilder& props)
  528. {
  529. props.add (new BooleanPropertyComponent (androidInternetNeeded.getPropertyAsValue(), "Internet Access", "Specify internet access permission in the manifest"),
  530. "If enabled, this will set the android.permission.INTERNET flag in the manifest.");
  531. props.add (new BooleanPropertyComponent (androidMicNeeded.getPropertyAsValue(), "Audio Input Required", "Specify audio record permission in the manifest"),
  532. "If enabled, this will set the android.permission.RECORD_AUDIO flag in the manifest.");
  533. props.add (new BooleanPropertyComponent (androidBluetoothNeeded.getPropertyAsValue(), "Bluetooth permissions Required", "Specify bluetooth permission (required for Bluetooth MIDI)"),
  534. "If enabled, this will set the android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN flag in the manifest. This is required for Bluetooth MIDI on Android.");
  535. props.add (new TextPropertyComponent (androidOtherPermissions.getPropertyAsValue(), "Custom permissions", 2048, false),
  536. "A space-separated list of other permission flags that should be added to the manifest.");
  537. }
  538. //==============================================================================
  539. void createCodeSigningExporterProperties (PropertyListBuilder& props)
  540. {
  541. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyStore, "Key Signing: key.store", 2048),
  542. "The key.store value, used when signing the release package.");
  543. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyStorePass, "Key Signing: key.store.password", 2048),
  544. "The key.store password, used when signing the release package.");
  545. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyAlias, "Key Signing: key.alias", 2048),
  546. "The key.alias value, used when signing the release package.");
  547. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyAliasPass, "Key Signing: key.alias.password", 2048),
  548. "The key.alias password, used when signing the release package.");
  549. }
  550. //==============================================================================
  551. void createOtherExporterProperties (PropertyListBuilder& props)
  552. {
  553. props.add (new TextPropertyComponent (androidTheme.getPropertyAsValue(), "Android Theme", 256, false),
  554. "E.g. @android:style/Theme.NoTitleBar or leave blank for default");
  555. }
  556. //==============================================================================
  557. String createDefaultClassName() const
  558. {
  559. String s (project.getBundleIdentifier().toString().toLowerCase());
  560. if (s.length() > 5
  561. && s.containsChar ('.')
  562. && s.containsOnly ("abcdefghijklmnopqrstuvwxyz_.")
  563. && ! s.startsWithChar ('.'))
  564. {
  565. if (! s.endsWithChar ('.'))
  566. s << ".";
  567. }
  568. else
  569. {
  570. s = "com.yourcompany.";
  571. }
  572. return s + CodeHelpers::makeValidIdentifier (project.getProjectFilenameRoot(), false, true, false);
  573. }
  574. void initialiseDependencyPathValues()
  575. {
  576. sdkPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::androidSDKPath),
  577. Ids::androidSDKPath, TargetOS::getThisOS())));
  578. ndkPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::androidNDKPath),
  579. Ids::androidNDKPath, TargetOS::getThisOS())));
  580. }
  581. //==============================================================================
  582. void copyActivityJavaFiles (const OwnedArray<LibraryModule>& modules, const File& targetFolder, const String& package) const
  583. {
  584. const String className (getActivityName());
  585. if (className.isEmpty())
  586. throw SaveError ("Invalid Android Activity class name: " + androidActivityClass.get());
  587. createDirectoryOrThrow (targetFolder);
  588. LibraryModule* const coreModule = getCoreModule (modules);
  589. if (coreModule != nullptr)
  590. {
  591. File javaDestFile (targetFolder.getChildFile (className + ".java"));
  592. File javaSourceFolder (coreModule->getFolder().getChildFile ("native")
  593. .getChildFile ("java"));
  594. String juceMidiCode, juceMidiImports, juceRuntimePermissionsCode;
  595. juceMidiImports << newLine;
  596. if (androidMinimumSDK.get().getIntValue() >= 23)
  597. {
  598. File javaAndroidMidi (javaSourceFolder.getChildFile ("AndroidMidi.java"));
  599. File javaRuntimePermissions (javaSourceFolder.getChildFile ("AndroidRuntimePermissions.java"));
  600. juceMidiImports << "import android.media.midi.*;" << newLine
  601. << "import android.bluetooth.*;" << newLine
  602. << "import android.bluetooth.le.*;" << newLine;
  603. juceMidiCode = javaAndroidMidi.loadFileAsString().replace ("JuceAppActivity", className);
  604. juceRuntimePermissionsCode = javaRuntimePermissions.loadFileAsString().replace ("JuceAppActivity", className);
  605. }
  606. else
  607. {
  608. juceMidiCode = javaSourceFolder.getChildFile ("AndroidMidiFallback.java")
  609. .loadFileAsString()
  610. .replace ("JuceAppActivity", className);
  611. }
  612. File javaSourceFile (javaSourceFolder.getChildFile ("JuceAppActivity.java"));
  613. StringArray javaSourceLines (StringArray::fromLines (javaSourceFile.loadFileAsString()));
  614. {
  615. MemoryOutputStream newFile;
  616. for (int i = 0; i < javaSourceLines.size(); ++i)
  617. {
  618. const String& line = javaSourceLines[i];
  619. if (line.contains ("$$JuceAndroidMidiImports$$"))
  620. newFile << juceMidiImports;
  621. else if (line.contains ("$$JuceAndroidMidiCode$$"))
  622. newFile << juceMidiCode;
  623. else if (line.contains ("$$JuceAndroidRuntimePermissionsCode$$"))
  624. newFile << juceRuntimePermissionsCode;
  625. else
  626. newFile << line.replace ("JuceAppActivity", className)
  627. .replace ("package com.juce;", "package " + package + ";") << newLine;
  628. }
  629. javaSourceLines = StringArray::fromLines (newFile.toString());
  630. }
  631. while (javaSourceLines.size() > 2
  632. && javaSourceLines[javaSourceLines.size() - 1].trim().isEmpty()
  633. && javaSourceLines[javaSourceLines.size() - 2].trim().isEmpty())
  634. javaSourceLines.remove (javaSourceLines.size() - 1);
  635. overwriteFileIfDifferentOrThrow (javaDestFile, javaSourceLines.joinIntoString (newLine));
  636. }
  637. }
  638. String getActivityName() const
  639. {
  640. return androidActivityClass.get().fromLastOccurrenceOf (".", false, false);
  641. }
  642. String getActivitySubClassName() const
  643. {
  644. String activityPath = androidActivitySubClassName.get();
  645. return (activityPath.isEmpty()) ? getActivityName() : activityPath.fromLastOccurrenceOf (".", false, false);
  646. }
  647. String getActivityClassPackage() const
  648. {
  649. return androidActivityClass.get().upToLastOccurrenceOf (".", false, false);
  650. }
  651. String getJNIActivityClassName() const
  652. {
  653. return androidActivityClass.get().replaceCharacter ('.', '/');
  654. }
  655. static LibraryModule* getCoreModule (const OwnedArray<LibraryModule>& modules)
  656. {
  657. for (int i = modules.size(); --i >= 0;)
  658. if (modules.getUnchecked(i)->getID() == "juce_core")
  659. return modules.getUnchecked(i);
  660. return nullptr;
  661. }
  662. //==============================================================================
  663. String getNativeModuleBinaryName (const AndroidBuildConfiguration& config) const
  664. {
  665. return (isLibrary() ? File::createLegalFileName (config.getTargetBinaryNameString().trim()) : "juce_jni");
  666. }
  667. String getAppPlatform() const
  668. {
  669. int ndkVersion = androidMinimumSDK.get().getIntValue();
  670. if (ndkVersion == 9)
  671. ndkVersion = 10; // (doesn't seem to be a version '9')
  672. return "android-" + String (ndkVersion);
  673. }
  674. //==============================================================================
  675. void writeStringsXML (const File& folder) const
  676. {
  677. XmlElement strings ("resources");
  678. XmlElement* resourceName = strings.createNewChildElement ("string");
  679. resourceName->setAttribute ("name", "app_name");
  680. resourceName->addTextElement (projectName);
  681. writeXmlOrThrow (strings, folder.getChildFile ("app/src/main/res/values/string.xml"), "utf-8", 100, true);
  682. }
  683. void writeAndroidManifest (const File& folder) const
  684. {
  685. ScopedPointer<XmlElement> manifest (createManifestXML());
  686. writeXmlOrThrow (*manifest, folder.getChildFile ("src/main/AndroidManifest.xml"), "utf-8", 100, true);
  687. }
  688. void writeIcon (const File& file, const Image& im) const
  689. {
  690. if (im.isValid())
  691. {
  692. createDirectoryOrThrow (file.getParentDirectory());
  693. PNGImageFormat png;
  694. MemoryOutputStream mo;
  695. if (! png.writeImageToStream (im, mo))
  696. throw SaveError ("Can't generate Android icon file");
  697. overwriteFileIfDifferentOrThrow (file, mo);
  698. }
  699. }
  700. void writeIcons (const File& folder) const
  701. {
  702. ScopedPointer<Drawable> bigIcon (getBigIcon());
  703. ScopedPointer<Drawable> smallIcon (getSmallIcon());
  704. if (bigIcon != nullptr && smallIcon != nullptr)
  705. {
  706. const int step = jmax (bigIcon->getWidth(), bigIcon->getHeight()) / 8;
  707. writeIcon (folder.getChildFile ("drawable-xhdpi/icon.png"), getBestIconForSize (step * 8, false));
  708. writeIcon (folder.getChildFile ("drawable-hdpi/icon.png"), getBestIconForSize (step * 6, false));
  709. writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), getBestIconForSize (step * 4, false));
  710. writeIcon (folder.getChildFile ("drawable-ldpi/icon.png"), getBestIconForSize (step * 3, false));
  711. }
  712. else if (Drawable* icon = bigIcon != nullptr ? bigIcon : smallIcon)
  713. {
  714. writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), rescaleImageForIcon (*icon, icon->getWidth()));
  715. }
  716. }
  717. void writeAppIcons (const File& folder) const
  718. {
  719. writeIcons (folder.getChildFile ("app/src/main/res/"));
  720. }
  721. static String sanitisePath (String path)
  722. {
  723. return expandHomeFolderToken (path).replace ("\\", "\\\\");
  724. }
  725. static String expandHomeFolderToken (const String& path)
  726. {
  727. String homeFolder = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
  728. return path.replace ("${user.home}", homeFolder)
  729. .replace ("~", homeFolder);
  730. }
  731. //==============================================================================
  732. void addCompileUnits (const Project::Item& projectItem, MemoryOutputStream& mo, Array<RelativePath>& excludeFromBuild) const
  733. {
  734. if (projectItem.isGroup())
  735. {
  736. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  737. addCompileUnits (projectItem.getChild(i), mo, excludeFromBuild);
  738. }
  739. else if (projectItem.shouldBeAddedToTargetProject())
  740. {
  741. const RelativePath file (projectItem.getFile(), getTargetFolder().getChildFile ("app"), RelativePath::buildTargetFolder);
  742. const ProjectType::Target::Type targetType = getProject().getTargetTypeFromFilePath (projectItem.getFile(), true);
  743. mo << " \"" << file.toUnixStyle() << "\"" << newLine;
  744. if ((! projectItem.shouldBeCompiled()) || (! shouldFileBeCompiledByDefault (file))
  745. || (getProject().getProjectType().isAudioPlugin()
  746. && targetType != ProjectType::Target::SharedCodeTarget
  747. && targetType != ProjectType::Target::StandalonePlugIn))
  748. excludeFromBuild.add (file);
  749. }
  750. }
  751. void addCompileUnits (MemoryOutputStream& mo, Array<RelativePath>& excludeFromBuild) const
  752. {
  753. for (int i = 0; i < getAllGroups().size(); ++i)
  754. addCompileUnits (getAllGroups().getReference(i), mo, excludeFromBuild);
  755. }
  756. //==============================================================================
  757. StringArray getCmakeDefinitions() const
  758. {
  759. const String toolchain = gradleToolchain.get();
  760. const bool isClang = (toolchain == "clang");
  761. StringArray cmakeArgs;
  762. cmakeArgs.add ("\"-DANDROID_TOOLCHAIN=" + toolchain + "\"");
  763. cmakeArgs.add ("\"-DANDROID_PLATFORM=" + getAppPlatform() + "\"");
  764. cmakeArgs.add (String ("\"-DANDROID_STL=") + (isClang ? "c++_static" : "gnustl_static") + "\"");
  765. cmakeArgs.add ("\"-DANDROID_CPP_FEATURES=exceptions rtti\"");
  766. cmakeArgs.add ("\"-DANDROID_ARM_MODE=arm\"");
  767. cmakeArgs.add ("\"-DANDROID_ARM_NEON=TRUE\"");
  768. return cmakeArgs;
  769. }
  770. //==============================================================================
  771. StringArray getAndroidCompilerFlags() const
  772. {
  773. StringArray cFlags;
  774. cFlags.add ("\"-fsigned-char\"");
  775. return cFlags;
  776. }
  777. StringArray getAndroidCxxCompilerFlags() const
  778. {
  779. StringArray cxxFlags (getAndroidCompilerFlags());
  780. cxxFlags.add ("\"-std=gnu++11\"");
  781. return cxxFlags;
  782. }
  783. StringArray getProjectCompilerFlags() const
  784. {
  785. StringArray cFlags (getAndroidCompilerFlags());
  786. cFlags.addArray (getEscapedFlags (StringArray::fromTokens (getExtraCompilerFlagsString(), true)));
  787. return cFlags;
  788. }
  789. StringArray getProjectCxxCompilerFlags() const
  790. {
  791. StringArray cxxFlags (getAndroidCxxCompilerFlags());
  792. cxxFlags.addArray (getEscapedFlags (StringArray::fromTokens (getExtraCompilerFlagsString(), true)));
  793. return cxxFlags;
  794. }
  795. //==============================================================================
  796. StringPairArray getAndroidPreprocessorDefs() const
  797. {
  798. StringPairArray defines;
  799. defines.set ("JUCE_ANDROID", "1");
  800. defines.set ("JUCE_ANDROID_API_VERSION", androidMinimumSDK.get());
  801. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSNAME", getJNIActivityClassName().replaceCharacter ('/', '_'));
  802. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSPATH", "\"" + getJNIActivityClassName() + "\"");
  803. return defines;
  804. }
  805. StringPairArray getProjectPreprocessorDefs() const
  806. {
  807. StringPairArray defines (getAndroidPreprocessorDefs());
  808. return mergePreprocessorDefs (defines, getProject().getPreprocessorDefs());
  809. }
  810. StringPairArray getConfigPreprocessorDefs (const BuildConfiguration& config) const
  811. {
  812. StringPairArray cfgDefines (config.getUniquePreprocessorDefs());
  813. if (config.isDebug())
  814. {
  815. cfgDefines.set ("DEBUG", "1");
  816. cfgDefines.set ("_DEBUG", "1");
  817. }
  818. else
  819. {
  820. cfgDefines.set ("NDEBUG", "1");
  821. }
  822. return cfgDefines;
  823. }
  824. //==============================================================================
  825. StringArray getAndroidLibraries() const
  826. {
  827. StringArray libraries;
  828. libraries.add ("log");
  829. libraries.add ("android");
  830. libraries.add (androidMinimumSDK.get().getIntValue() >= 18 ? "GLESv3" : "GLESv2");
  831. libraries.add ("EGL");
  832. return libraries;
  833. }
  834. StringArray getProjectLibraries() const
  835. {
  836. StringArray libraries (getAndroidLibraries());
  837. libraries.addArray (StringArray::fromLines (getExternalLibrariesString()));
  838. return libraries;
  839. }
  840. //==============================================================================
  841. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  842. {
  843. StringArray paths (extraSearchPaths);
  844. paths.addArray (config.getHeaderSearchPaths());
  845. paths = getCleanedStringArray (paths);
  846. return paths;
  847. }
  848. //==============================================================================
  849. String escapeDirectoryForCmake (const String& path) const
  850. {
  851. RelativePath relative =
  852. RelativePath (path, RelativePath::buildTargetFolder)
  853. .rebased (getTargetFolder(), getTargetFolder().getChildFile ("app"), RelativePath::buildTargetFolder);
  854. return relative.toUnixStyle();
  855. }
  856. void writeCmakePathLines (MemoryOutputStream& mo, const String& prefix, const String& firstLine, const StringArray& paths) const
  857. {
  858. if (paths.size() > 0)
  859. {
  860. mo << prefix << firstLine << newLine;
  861. for (auto& path : paths)
  862. mo << prefix << " \"" << escapeDirectoryForCmake (path) << "\"" << newLine;
  863. mo << prefix << ")" << newLine << newLine;
  864. }
  865. }
  866. static StringArray getEscapedPreprocessorDefs (const StringPairArray& defs)
  867. {
  868. StringArray escapedDefs;
  869. for (int i = 0; i < defs.size(); ++i)
  870. {
  871. String escaped ("\"-D" + defs.getAllKeys()[i]);
  872. String value = defs.getAllValues()[i];
  873. if (value.isNotEmpty())
  874. {
  875. value = value.replace ("\"", "\\\"");
  876. if (value.containsChar (L' '))
  877. value = "\\\"" + value + "\\\"";
  878. escaped += ("=" + value + "\"");
  879. }
  880. escapedDefs.add (escaped);
  881. }
  882. return escapedDefs;
  883. }
  884. static StringArray getEscapedFlags (const StringArray& flags)
  885. {
  886. StringArray escaped;
  887. for (auto& flag : flags)
  888. escaped.add ("\"" + flag + "\"");
  889. return escaped;
  890. }
  891. //==============================================================================
  892. XmlElement* createManifestXML() const
  893. {
  894. XmlElement* manifest = new XmlElement ("manifest");
  895. manifest->setAttribute ("xmlns:android", "http://schemas.android.com/apk/res/android");
  896. manifest->setAttribute ("android:versionCode", androidVersionCode.get());
  897. manifest->setAttribute ("android:versionName", project.getVersionString());
  898. manifest->setAttribute ("package", getActivityClassPackage());
  899. if (! isLibrary())
  900. {
  901. XmlElement* screens = manifest->createNewChildElement ("supports-screens");
  902. screens->setAttribute ("android:smallScreens", "true");
  903. screens->setAttribute ("android:normalScreens", "true");
  904. screens->setAttribute ("android:largeScreens", "true");
  905. screens->setAttribute ("android:anyDensity", "true");
  906. }
  907. XmlElement* sdk = manifest->createNewChildElement ("uses-sdk");
  908. sdk->setAttribute ("android:minSdkVersion", androidMinimumSDK.get());
  909. sdk->setAttribute ("android:targetSdkVersion", androidMinimumSDK.get());
  910. {
  911. const StringArray permissions (getPermissionsRequired());
  912. for (int i = permissions.size(); --i >= 0;)
  913. manifest->createNewChildElement ("uses-permission")->setAttribute ("android:name", permissions[i]);
  914. }
  915. if (project.getModules().isModuleEnabled ("juce_opengl"))
  916. {
  917. XmlElement* feature = manifest->createNewChildElement ("uses-feature");
  918. feature->setAttribute ("android:glEsVersion", (androidMinimumSDK.get().getIntValue() >= 18 ? "0x00030000" : "0x00020000"));
  919. feature->setAttribute ("android:required", "true");
  920. }
  921. if (! isLibrary())
  922. {
  923. XmlElement* app = manifest->createNewChildElement ("application");
  924. app->setAttribute ("android:label", "@string/app_name");
  925. if (androidTheme.get().isNotEmpty())
  926. app->setAttribute ("android:theme", androidTheme.get());
  927. {
  928. ScopedPointer<Drawable> bigIcon (getBigIcon()), smallIcon (getSmallIcon());
  929. if (bigIcon != nullptr || smallIcon != nullptr)
  930. app->setAttribute ("android:icon", "@drawable/icon");
  931. }
  932. if (androidMinimumSDK.get().getIntValue() >= 11)
  933. app->setAttribute ("android:hardwareAccelerated", "false"); // (using the 2D acceleration slows down openGL)
  934. XmlElement* act = app->createNewChildElement ("activity");
  935. act->setAttribute ("android:name", getActivitySubClassName());
  936. act->setAttribute ("android:label", "@string/app_name");
  937. String configChanges ("keyboardHidden|orientation");
  938. if (androidMinimumSDK.get().getIntValue() >= 13)
  939. configChanges += "|screenSize";
  940. act->setAttribute ("android:configChanges", configChanges);
  941. act->setAttribute ("android:screenOrientation", androidScreenOrientation.get());
  942. XmlElement* intent = act->createNewChildElement ("intent-filter");
  943. intent->createNewChildElement ("action")->setAttribute ("android:name", "android.intent.action.MAIN");
  944. intent->createNewChildElement ("category")->setAttribute ("android:name", "android.intent.category.LAUNCHER");
  945. }
  946. return manifest;
  947. }
  948. StringArray getPermissionsRequired() const
  949. {
  950. StringArray s;
  951. s.addTokens (androidOtherPermissions.get(), ", ", "");
  952. if (androidInternetNeeded.get())
  953. s.add ("android.permission.INTERNET");
  954. if (androidMicNeeded.get())
  955. s.add ("android.permission.RECORD_AUDIO");
  956. if (androidBluetoothNeeded.get())
  957. {
  958. s.add ("android.permission.BLUETOOTH");
  959. s.add ("android.permission.BLUETOOTH_ADMIN");
  960. s.add ("android.permission.ACCESS_COARSE_LOCATION");
  961. }
  962. return getCleanedStringArray (s);
  963. }
  964. //==============================================================================
  965. bool isLibrary() const
  966. {
  967. return getProject().getProjectType().isDynamicLibrary()
  968. || getProject().getProjectType().isStaticLibrary();
  969. }
  970. static String toGradleList (const StringArray& array)
  971. {
  972. StringArray escapedArray;
  973. for (auto element : array)
  974. escapedArray.add ("\"" + element.replace ("\\", "\\\\").replace ("\"", "\\\"") + "\"");
  975. return escapedArray.joinIntoString (", ");
  976. }
  977. //==============================================================================
  978. Value sdkPath, ndkPath;
  979. const File AndroidExecutable;
  980. JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter)
  981. };
  982. ProjectExporter* createAndroidExporter (Project& p, const ValueTree& t)
  983. {
  984. return new AndroidProjectExporter (p, t);
  985. }
  986. ProjectExporter* createAndroidExporterForSetting (Project& p, const ValueTree& t)
  987. {
  988. return AndroidProjectExporter::createForSettings (p, t);
  989. }