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.

1283 lines
56KB

  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. ProjectExporter::BuildConfiguration::Ptr config (getConfiguration(0));
  308. if (config)
  309. {
  310. if (const auto* cfg = dynamic_cast<const AndroidBuildConfiguration*> (config.get()))
  311. {
  312. mo << "ELSE(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg->getProductFlavourCMakeIdentifier() <<"\")" << newLine;
  313. mo << " MESSAGE( FATAL_ERROR \"No matching build-configuration found.\" )" << newLine;
  314. mo << "ENDIF(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg->getProductFlavourCMakeIdentifier() <<"\")" << newLine << newLine;
  315. }
  316. }
  317. }
  318. }
  319. Array<RelativePath> excludeFromBuild;
  320. mo << "add_library( ${BINARY_NAME}" << newLine;
  321. mo << newLine;
  322. mo << " " << (getProject().getProjectType().isStaticLibrary() ? "STATIC" : "SHARED") << newLine;
  323. mo << newLine;
  324. addCompileUnits (mo, excludeFromBuild);
  325. mo << ")" << newLine << newLine;
  326. if (excludeFromBuild.size() > 0)
  327. {
  328. for (auto& exclude : excludeFromBuild)
  329. mo << "set_source_files_properties(\"" << exclude.toUnixStyle() << "\" PROPERTIES HEADER_FILE_ONLY TRUE)" << newLine;
  330. mo << newLine;
  331. }
  332. const StringArray& libraries = getProjectLibraries();
  333. if (libraries.size() > 0)
  334. {
  335. for (auto& lib : libraries)
  336. mo << "find_library(" << lib.toLowerCase().replaceCharacter (L' ', L'_') << " \"" << lib << "\")" << newLine;
  337. mo << newLine;
  338. }
  339. mo << "target_link_libraries( ${BINARY_NAME}";
  340. if (libraries.size() > 0)
  341. {
  342. mo << newLine << newLine;
  343. for (auto& lib : libraries)
  344. mo << " ${" << lib.toLowerCase().replaceCharacter (L' ', L'_') << "}" << newLine;
  345. }
  346. mo << ")" << newLine;
  347. overwriteFileIfDifferentOrThrow (file, mo);
  348. }
  349. //==============================================================================
  350. String getProjectBuildGradleFileContent() const
  351. {
  352. MemoryOutputStream mo;
  353. mo << "buildscript {" << newLine;
  354. mo << " repositories {" << newLine;
  355. mo << " jcenter()" << newLine;
  356. mo << " }" << newLine;
  357. mo << " dependencies {" << newLine;
  358. mo << " classpath 'com.android.tools.build:gradle:" << androidPluginVersion.get() << "'" << newLine;
  359. mo << " }" << newLine;
  360. mo << "}" << newLine;
  361. mo << "" << newLine;
  362. mo << "allprojects {" << newLine;
  363. mo << " repositories {" << newLine;
  364. mo << " jcenter()" << newLine;
  365. mo << " }" << newLine;
  366. mo << "}" << newLine;
  367. return mo.toString();
  368. }
  369. //==============================================================================
  370. String getAppBuildGradleFileContent () const
  371. {
  372. MemoryOutputStream mo;
  373. mo << "apply plugin: 'com.android." << (isLibrary() ? "library" : "application") << "'" << newLine << newLine;
  374. mo << "android {" << newLine;
  375. mo << " compileSdkVersion " << androidMinimumSDK.get().getIntValue() << newLine;
  376. mo << " buildToolsVersion \"" << buildToolsVersion.get() << "\"" << newLine;
  377. mo << " externalNativeBuild {" << newLine;
  378. mo << " cmake {" << newLine;
  379. mo << " path \"CMakeLists.txt\"" << newLine;
  380. mo << " }" << newLine;
  381. mo << " }" << newLine;
  382. mo << getAndroidSigningConfig() << newLine;
  383. mo << getAndroidDefaultConfig() << newLine;
  384. mo << getAndroidBuildTypes() << newLine;
  385. mo << getAndroidProductFlavours() << newLine;
  386. mo << getAndroidVariantFilter() << newLine;
  387. mo << "}" << newLine;
  388. return mo.toString();
  389. }
  390. String getAndroidProductFlavours() const
  391. {
  392. MemoryOutputStream mo;
  393. mo << " productFlavors {" << newLine;
  394. for (ConstConfigIterator config (*this); config.next();)
  395. {
  396. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  397. mo << " " << cfg.getProductFlavourNameIdentifier() << " {" << newLine;
  398. if (cfg.getArchitectures().isNotEmpty())
  399. {
  400. mo << " ndk {" << newLine;
  401. mo << " abiFilters " << toGradleList (StringArray::fromTokens (cfg.getArchitectures(), " ", "")) << newLine;
  402. mo << " }" << newLine;
  403. }
  404. mo << " externalNativeBuild {" << newLine;
  405. mo << " cmake {" << newLine;
  406. if (getProject().getProjectType().isStaticLibrary())
  407. mo << " targets \"" << getNativeModuleBinaryName (cfg) << "\"" << newLine;
  408. mo << " arguments \"-DJUCE_BUILD_CONFIGFURATION=" << cfg.getProductFlavourCMakeIdentifier() << "\"" << newLine;
  409. mo << " cFlags \"-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
  410. mo << " cppFlags \"-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
  411. mo << " }" << newLine;
  412. mo << " }" << newLine;
  413. mo << " }" << newLine;
  414. }
  415. mo << " }" << newLine;
  416. return mo.toString();
  417. }
  418. String getAndroidSigningConfig() const
  419. {
  420. MemoryOutputStream mo;
  421. String keyStoreFilePath = androidKeyStore.get().replace ("${user.home}", "${System.properties['user.home']}")
  422. .replace ("/", "${File.separator}");
  423. mo << " signingConfigs {" << newLine;
  424. mo << " release {" << newLine;
  425. mo << " storeFile file(\"" << keyStoreFilePath << "\")" << newLine;
  426. mo << " storePassword \"" << androidKeyStorePass.get() << "\"" << newLine;
  427. mo << " keyAlias \"" << androidKeyAlias.get() << "\"" << newLine;
  428. mo << " keyPassword \"" << androidKeyAliasPass.get() << "\"" << newLine;
  429. mo << " storeType \"jks\"" << newLine;
  430. mo << " }" << newLine;
  431. mo << " }" << newLine;
  432. return mo.toString();
  433. }
  434. String getAndroidDefaultConfig() const
  435. {
  436. const String bundleIdentifier = project.getBundleIdentifier().toString().toLowerCase();
  437. const StringArray& cmakeDefs = getCmakeDefinitions();
  438. const StringArray& cFlags = getProjectCompilerFlags();
  439. const StringArray& cxxFlags = getProjectCxxCompilerFlags();
  440. const int minSdkVersion = androidMinimumSDK.get().getIntValue();
  441. MemoryOutputStream mo;
  442. mo << " defaultConfig {" << newLine;
  443. if (! isLibrary())
  444. mo << " applicationId \"" << bundleIdentifier << "\"" << newLine;
  445. mo << " minSdkVersion " << minSdkVersion << newLine;
  446. mo << " targetSdkVersion " << minSdkVersion << newLine;
  447. mo << " externalNativeBuild {" << newLine;
  448. mo << " cmake {" << newLine;
  449. mo << " arguments " << cmakeDefs.joinIntoString (", ") << newLine;
  450. if (cFlags.size() > 0)
  451. mo << " cFlags " << cFlags.joinIntoString (", ") << newLine;
  452. if (cxxFlags.size() > 0)
  453. mo << " cppFlags " << cxxFlags.joinIntoString (", ") << newLine;
  454. mo << " }" << newLine;
  455. mo << " }" << newLine;
  456. mo << " }" << newLine;
  457. return mo.toString();
  458. }
  459. String getAndroidBuildTypes() const
  460. {
  461. MemoryOutputStream mo;
  462. mo << " buildTypes {" << newLine;
  463. int numDebugConfigs = 0;
  464. const int numConfigs = getNumConfigurations();
  465. for (int i = 0; i < numConfigs; ++i)
  466. {
  467. auto config = getConfiguration(i);
  468. if (config->isDebug()) numDebugConfigs++;
  469. if (numDebugConfigs > 1 || ((numConfigs - numDebugConfigs) > 1))
  470. continue;
  471. mo << " " << (config->isDebug() ? "debug" : "release") << " {" << newLine;
  472. mo << " initWith " << (config->isDebug() ? "debug" : "release") << newLine;
  473. mo << " debuggable " << (config->isDebug() ? "true" : "false") << newLine;
  474. mo << " jniDebuggable " << (config->isDebug() ? "true" : "false") << newLine;
  475. if (! config->isDebug())
  476. mo << " signingConfig signingConfigs.release" << newLine;
  477. mo << " }" << newLine;
  478. }
  479. mo << " }" << newLine;
  480. return mo.toString();
  481. }
  482. String getAndroidVariantFilter() const
  483. {
  484. MemoryOutputStream mo;
  485. mo << " variantFilter { variant ->" << newLine;
  486. mo << " def names = variant.flavors*.name" << newLine;
  487. for (ConstConfigIterator config (*this); config.next();)
  488. {
  489. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  490. mo << " if (names.contains (\"" << cfg.getProductFlavourNameIdentifier() << "\")" << newLine;
  491. mo << " && variant.buildType.name != \"" << (cfg.isDebug() ? "debug" : "release") << "\") {" << newLine;
  492. mo << " setIgnore(true)" << newLine;
  493. mo << " }" << newLine;
  494. }
  495. mo << " }" << newLine;
  496. return mo.toString();
  497. }
  498. //==============================================================================
  499. String getLocalPropertiesFileContent() const
  500. {
  501. String props;
  502. props << "ndk.dir=" << sanitisePath (ndkPath.toString()) << newLine
  503. << "sdk.dir=" << sanitisePath (sdkPath.toString()) << newLine;
  504. return props;
  505. }
  506. String getGradleWrapperPropertiesFileContent() const
  507. {
  508. String props;
  509. props << "distributionUrl=https\\://services.gradle.org/distributions/gradle-"
  510. << gradleVersion.get() << "-all.zip";
  511. return props;
  512. }
  513. //==============================================================================
  514. void createBaseExporterProperties (PropertyListBuilder& props)
  515. {
  516. static const char* orientations[] = { "Portrait and Landscape", "Portrait", "Landscape", nullptr };
  517. static const char* orientationValues[] = { "unspecified", "portrait", "landscape", nullptr };
  518. props.add (new ChoicePropertyComponent (androidScreenOrientation.getPropertyAsValue(), "Screen orientation", StringArray (orientations), Array<var> (orientationValues)),
  519. "The screen orientations that this app should support");
  520. props.add (new TextWithDefaultPropertyComponent<String> (androidActivityClass, "Android Activity class name", 256),
  521. "The full java class name to use for the app's Activity class.");
  522. props.add (new TextPropertyComponent (androidActivitySubClassName.getPropertyAsValue(), "Android Activity sub-class name", 256, false),
  523. "If not empty, specifies the Android Activity class name stored in the app's manifest. "
  524. "Use this if you would like to use your own Android Activity sub-class.");
  525. props.add (new TextWithDefaultPropertyComponent<String> (androidVersionCode, "Android Version Code", 32),
  526. "An integer value that represents the version of the application code, relative to other versions.");
  527. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), sdkPath, "Android SDK Path"),
  528. "The path to the Android SDK folder on the target build machine");
  529. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), ndkPath, "Android NDK Path"),
  530. "The path to the Android NDK folder on the target build machine");
  531. props.add (new TextWithDefaultPropertyComponent<String> (androidMinimumSDK, "Minimum SDK version", 32),
  532. "The number of the minimum version of the Android SDK that the app requires");
  533. }
  534. //==============================================================================
  535. void createManifestExporterProperties (PropertyListBuilder& props)
  536. {
  537. props.add (new BooleanPropertyComponent (androidInternetNeeded.getPropertyAsValue(), "Internet Access", "Specify internet access permission in the manifest"),
  538. "If enabled, this will set the android.permission.INTERNET flag in the manifest.");
  539. props.add (new BooleanPropertyComponent (androidMicNeeded.getPropertyAsValue(), "Audio Input Required", "Specify audio record permission in the manifest"),
  540. "If enabled, this will set the android.permission.RECORD_AUDIO flag in the manifest.");
  541. props.add (new BooleanPropertyComponent (androidBluetoothNeeded.getPropertyAsValue(), "Bluetooth permissions Required", "Specify bluetooth permission (required for Bluetooth MIDI)"),
  542. "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.");
  543. props.add (new TextPropertyComponent (androidOtherPermissions.getPropertyAsValue(), "Custom permissions", 2048, false),
  544. "A space-separated list of other permission flags that should be added to the manifest.");
  545. }
  546. //==============================================================================
  547. void createCodeSigningExporterProperties (PropertyListBuilder& props)
  548. {
  549. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyStore, "Key Signing: key.store", 2048),
  550. "The key.store value, used when signing the release package.");
  551. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyStorePass, "Key Signing: key.store.password", 2048),
  552. "The key.store password, used when signing the release package.");
  553. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyAlias, "Key Signing: key.alias", 2048),
  554. "The key.alias value, used when signing the release package.");
  555. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyAliasPass, "Key Signing: key.alias.password", 2048),
  556. "The key.alias password, used when signing the release package.");
  557. }
  558. //==============================================================================
  559. void createOtherExporterProperties (PropertyListBuilder& props)
  560. {
  561. props.add (new TextPropertyComponent (androidTheme.getPropertyAsValue(), "Android Theme", 256, false),
  562. "E.g. @android:style/Theme.NoTitleBar or leave blank for default");
  563. }
  564. //==============================================================================
  565. String createDefaultClassName() const
  566. {
  567. String s (project.getBundleIdentifier().toString().toLowerCase());
  568. if (s.length() > 5
  569. && s.containsChar ('.')
  570. && s.containsOnly ("abcdefghijklmnopqrstuvwxyz_.")
  571. && ! s.startsWithChar ('.'))
  572. {
  573. if (! s.endsWithChar ('.'))
  574. s << ".";
  575. }
  576. else
  577. {
  578. s = "com.yourcompany.";
  579. }
  580. return s + CodeHelpers::makeValidIdentifier (project.getProjectFilenameRoot(), false, true, false);
  581. }
  582. void initialiseDependencyPathValues()
  583. {
  584. sdkPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::androidSDKPath),
  585. Ids::androidSDKPath, TargetOS::getThisOS())));
  586. ndkPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::androidNDKPath),
  587. Ids::androidNDKPath, TargetOS::getThisOS())));
  588. }
  589. //==============================================================================
  590. void copyActivityJavaFiles (const OwnedArray<LibraryModule>& modules, const File& targetFolder, const String& package) const
  591. {
  592. const String className (getActivityName());
  593. if (className.isEmpty())
  594. throw SaveError ("Invalid Android Activity class name: " + androidActivityClass.get());
  595. createDirectoryOrThrow (targetFolder);
  596. LibraryModule* const coreModule = getCoreModule (modules);
  597. if (coreModule != nullptr)
  598. {
  599. File javaDestFile (targetFolder.getChildFile (className + ".java"));
  600. File javaSourceFolder (coreModule->getFolder().getChildFile ("native")
  601. .getChildFile ("java"));
  602. String juceMidiCode, juceMidiImports, juceRuntimePermissionsCode;
  603. juceMidiImports << newLine;
  604. if (androidMinimumSDK.get().getIntValue() >= 23)
  605. {
  606. File javaAndroidMidi (javaSourceFolder.getChildFile ("AndroidMidi.java"));
  607. File javaRuntimePermissions (javaSourceFolder.getChildFile ("AndroidRuntimePermissions.java"));
  608. juceMidiImports << "import android.media.midi.*;" << newLine
  609. << "import android.bluetooth.*;" << newLine
  610. << "import android.bluetooth.le.*;" << newLine;
  611. juceMidiCode = javaAndroidMidi.loadFileAsString().replace ("JuceAppActivity", className);
  612. juceRuntimePermissionsCode = javaRuntimePermissions.loadFileAsString().replace ("JuceAppActivity", className);
  613. }
  614. else
  615. {
  616. juceMidiCode = javaSourceFolder.getChildFile ("AndroidMidiFallback.java")
  617. .loadFileAsString()
  618. .replace ("JuceAppActivity", className);
  619. }
  620. File javaSourceFile (javaSourceFolder.getChildFile ("JuceAppActivity.java"));
  621. StringArray javaSourceLines (StringArray::fromLines (javaSourceFile.loadFileAsString()));
  622. {
  623. MemoryOutputStream newFile;
  624. for (int i = 0; i < javaSourceLines.size(); ++i)
  625. {
  626. const String& line = javaSourceLines[i];
  627. if (line.contains ("$$JuceAndroidMidiImports$$"))
  628. newFile << juceMidiImports;
  629. else if (line.contains ("$$JuceAndroidMidiCode$$"))
  630. newFile << juceMidiCode;
  631. else if (line.contains ("$$JuceAndroidRuntimePermissionsCode$$"))
  632. newFile << juceRuntimePermissionsCode;
  633. else
  634. newFile << line.replace ("JuceAppActivity", className)
  635. .replace ("package com.juce;", "package " + package + ";") << newLine;
  636. }
  637. javaSourceLines = StringArray::fromLines (newFile.toString());
  638. }
  639. while (javaSourceLines.size() > 2
  640. && javaSourceLines[javaSourceLines.size() - 1].trim().isEmpty()
  641. && javaSourceLines[javaSourceLines.size() - 2].trim().isEmpty())
  642. javaSourceLines.remove (javaSourceLines.size() - 1);
  643. overwriteFileIfDifferentOrThrow (javaDestFile, javaSourceLines.joinIntoString (newLine));
  644. }
  645. }
  646. String getActivityName() const
  647. {
  648. return androidActivityClass.get().fromLastOccurrenceOf (".", false, false);
  649. }
  650. String getActivitySubClassName() const
  651. {
  652. String activityPath = androidActivitySubClassName.get();
  653. return (activityPath.isEmpty()) ? getActivityName() : activityPath.fromLastOccurrenceOf (".", false, false);
  654. }
  655. String getActivityClassPackage() const
  656. {
  657. return androidActivityClass.get().upToLastOccurrenceOf (".", false, false);
  658. }
  659. String getJNIActivityClassName() const
  660. {
  661. return androidActivityClass.get().replaceCharacter ('.', '/');
  662. }
  663. static LibraryModule* getCoreModule (const OwnedArray<LibraryModule>& modules)
  664. {
  665. for (int i = modules.size(); --i >= 0;)
  666. if (modules.getUnchecked(i)->getID() == "juce_core")
  667. return modules.getUnchecked(i);
  668. return nullptr;
  669. }
  670. //==============================================================================
  671. String getNativeModuleBinaryName (const AndroidBuildConfiguration& config) const
  672. {
  673. return (isLibrary() ? File::createLegalFileName (config.getTargetBinaryNameString().trim()) : "juce_jni");
  674. }
  675. String getAppPlatform() const
  676. {
  677. int ndkVersion = androidMinimumSDK.get().getIntValue();
  678. if (ndkVersion == 9)
  679. ndkVersion = 10; // (doesn't seem to be a version '9')
  680. return "android-" + String (ndkVersion);
  681. }
  682. //==============================================================================
  683. void writeStringsXML (const File& folder) const
  684. {
  685. XmlElement strings ("resources");
  686. XmlElement* resourceName = strings.createNewChildElement ("string");
  687. resourceName->setAttribute ("name", "app_name");
  688. resourceName->addTextElement (projectName);
  689. writeXmlOrThrow (strings, folder.getChildFile ("app/src/main/res/values/string.xml"), "utf-8", 100, true);
  690. }
  691. void writeAndroidManifest (const File& folder) const
  692. {
  693. ScopedPointer<XmlElement> manifest (createManifestXML());
  694. writeXmlOrThrow (*manifest, folder.getChildFile ("src/main/AndroidManifest.xml"), "utf-8", 100, true);
  695. }
  696. void writeIcon (const File& file, const Image& im) const
  697. {
  698. if (im.isValid())
  699. {
  700. createDirectoryOrThrow (file.getParentDirectory());
  701. PNGImageFormat png;
  702. MemoryOutputStream mo;
  703. if (! png.writeImageToStream (im, mo))
  704. throw SaveError ("Can't generate Android icon file");
  705. overwriteFileIfDifferentOrThrow (file, mo);
  706. }
  707. }
  708. void writeIcons (const File& folder) const
  709. {
  710. ScopedPointer<Drawable> bigIcon (getBigIcon());
  711. ScopedPointer<Drawable> smallIcon (getSmallIcon());
  712. if (bigIcon != nullptr && smallIcon != nullptr)
  713. {
  714. const int step = jmax (bigIcon->getWidth(), bigIcon->getHeight()) / 8;
  715. writeIcon (folder.getChildFile ("drawable-xhdpi/icon.png"), getBestIconForSize (step * 8, false));
  716. writeIcon (folder.getChildFile ("drawable-hdpi/icon.png"), getBestIconForSize (step * 6, false));
  717. writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), getBestIconForSize (step * 4, false));
  718. writeIcon (folder.getChildFile ("drawable-ldpi/icon.png"), getBestIconForSize (step * 3, false));
  719. }
  720. else if (Drawable* icon = bigIcon != nullptr ? bigIcon : smallIcon)
  721. {
  722. writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), rescaleImageForIcon (*icon, icon->getWidth()));
  723. }
  724. }
  725. void writeAppIcons (const File& folder) const
  726. {
  727. writeIcons (folder.getChildFile ("app/src/main/res/"));
  728. }
  729. static String sanitisePath (String path)
  730. {
  731. return expandHomeFolderToken (path).replace ("\\", "\\\\");
  732. }
  733. static String expandHomeFolderToken (const String& path)
  734. {
  735. String homeFolder = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
  736. return path.replace ("${user.home}", homeFolder)
  737. .replace ("~", homeFolder);
  738. }
  739. //==============================================================================
  740. void addCompileUnits (const Project::Item& projectItem, MemoryOutputStream& mo, Array<RelativePath>& excludeFromBuild) const
  741. {
  742. if (projectItem.isGroup())
  743. {
  744. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  745. addCompileUnits (projectItem.getChild(i), mo, excludeFromBuild);
  746. }
  747. else if (projectItem.shouldBeAddedToTargetProject())
  748. {
  749. const RelativePath file (projectItem.getFile(), getTargetFolder().getChildFile ("app"), RelativePath::buildTargetFolder);
  750. const ProjectType::Target::Type targetType = getProject().getTargetTypeFromFilePath (projectItem.getFile(), true);
  751. mo << " \"" << file.toUnixStyle() << "\"" << newLine;
  752. if ((! projectItem.shouldBeCompiled()) || (! shouldFileBeCompiledByDefault (file))
  753. || (getProject().getProjectType().isAudioPlugin()
  754. && targetType != ProjectType::Target::SharedCodeTarget
  755. && targetType != ProjectType::Target::StandalonePlugIn))
  756. excludeFromBuild.add (file);
  757. }
  758. }
  759. void addCompileUnits (MemoryOutputStream& mo, Array<RelativePath>& excludeFromBuild) const
  760. {
  761. for (int i = 0; i < getAllGroups().size(); ++i)
  762. addCompileUnits (getAllGroups().getReference(i), mo, excludeFromBuild);
  763. }
  764. //==============================================================================
  765. StringArray getCmakeDefinitions() const
  766. {
  767. const String toolchain = gradleToolchain.get();
  768. const bool isClang = (toolchain == "clang");
  769. StringArray cmakeArgs;
  770. cmakeArgs.add ("\"-DANDROID_TOOLCHAIN=" + toolchain + "\"");
  771. cmakeArgs.add ("\"-DANDROID_PLATFORM=" + getAppPlatform() + "\"");
  772. cmakeArgs.add (String ("\"-DANDROID_STL=") + (isClang ? "c++_static" : "gnustl_static") + "\"");
  773. cmakeArgs.add ("\"-DANDROID_CPP_FEATURES=exceptions rtti\"");
  774. cmakeArgs.add ("\"-DANDROID_ARM_MODE=arm\"");
  775. cmakeArgs.add ("\"-DANDROID_ARM_NEON=TRUE\"");
  776. return cmakeArgs;
  777. }
  778. //==============================================================================
  779. StringArray getAndroidCompilerFlags() const
  780. {
  781. StringArray cFlags;
  782. cFlags.add ("\"-fsigned-char\"");
  783. return cFlags;
  784. }
  785. StringArray getAndroidCxxCompilerFlags() const
  786. {
  787. StringArray cxxFlags (getAndroidCompilerFlags());
  788. cxxFlags.add ("\"-std=gnu++11\"");
  789. return cxxFlags;
  790. }
  791. StringArray getProjectCompilerFlags() const
  792. {
  793. StringArray cFlags (getAndroidCompilerFlags());
  794. cFlags.addArray (getEscapedFlags (StringArray::fromTokens (getExtraCompilerFlagsString(), true)));
  795. return cFlags;
  796. }
  797. StringArray getProjectCxxCompilerFlags() const
  798. {
  799. StringArray cxxFlags (getAndroidCxxCompilerFlags());
  800. cxxFlags.addArray (getEscapedFlags (StringArray::fromTokens (getExtraCompilerFlagsString(), true)));
  801. return cxxFlags;
  802. }
  803. //==============================================================================
  804. StringPairArray getAndroidPreprocessorDefs() const
  805. {
  806. StringPairArray defines;
  807. defines.set ("JUCE_ANDROID", "1");
  808. defines.set ("JUCE_ANDROID_API_VERSION", androidMinimumSDK.get());
  809. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSNAME", getJNIActivityClassName().replaceCharacter ('/', '_'));
  810. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSPATH", "\"" + getJNIActivityClassName() + "\"");
  811. return defines;
  812. }
  813. StringPairArray getProjectPreprocessorDefs() const
  814. {
  815. StringPairArray defines (getAndroidPreprocessorDefs());
  816. return mergePreprocessorDefs (defines, getProject().getPreprocessorDefs());
  817. }
  818. StringPairArray getConfigPreprocessorDefs (const BuildConfiguration& config) const
  819. {
  820. StringPairArray cfgDefines (config.getUniquePreprocessorDefs());
  821. if (config.isDebug())
  822. {
  823. cfgDefines.set ("DEBUG", "1");
  824. cfgDefines.set ("_DEBUG", "1");
  825. }
  826. else
  827. {
  828. cfgDefines.set ("NDEBUG", "1");
  829. }
  830. return cfgDefines;
  831. }
  832. //==============================================================================
  833. StringArray getAndroidLibraries() const
  834. {
  835. StringArray libraries;
  836. libraries.add ("log");
  837. libraries.add ("android");
  838. libraries.add (androidMinimumSDK.get().getIntValue() >= 18 ? "GLESv3" : "GLESv2");
  839. libraries.add ("EGL");
  840. return libraries;
  841. }
  842. StringArray getProjectLibraries() const
  843. {
  844. StringArray libraries (getAndroidLibraries());
  845. libraries.addArray (StringArray::fromLines (getExternalLibrariesString()));
  846. return libraries;
  847. }
  848. //==============================================================================
  849. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  850. {
  851. StringArray paths (extraSearchPaths);
  852. paths.addArray (config.getHeaderSearchPaths());
  853. paths = getCleanedStringArray (paths);
  854. return paths;
  855. }
  856. //==============================================================================
  857. String escapeDirectoryForCmake (const String& path) const
  858. {
  859. RelativePath relative =
  860. RelativePath (path, RelativePath::buildTargetFolder)
  861. .rebased (getTargetFolder(), getTargetFolder().getChildFile ("app"), RelativePath::buildTargetFolder);
  862. return relative.toUnixStyle();
  863. }
  864. void writeCmakePathLines (MemoryOutputStream& mo, const String& prefix, const String& firstLine, const StringArray& paths) const
  865. {
  866. if (paths.size() > 0)
  867. {
  868. mo << prefix << firstLine << newLine;
  869. for (auto& path : paths)
  870. mo << prefix << " \"" << escapeDirectoryForCmake (path) << "\"" << newLine;
  871. mo << prefix << ")" << newLine << newLine;
  872. }
  873. }
  874. static StringArray getEscapedPreprocessorDefs (const StringPairArray& defs)
  875. {
  876. StringArray escapedDefs;
  877. for (int i = 0; i < defs.size(); ++i)
  878. {
  879. String escaped ("\"-D" + defs.getAllKeys()[i]);
  880. String value = defs.getAllValues()[i];
  881. if (value.isNotEmpty())
  882. {
  883. value = value.replace ("\"", "\\\"");
  884. if (value.containsChar (L' '))
  885. value = "\\\"" + value + "\\\"";
  886. escaped += ("=" + value + "\"");
  887. }
  888. escapedDefs.add (escaped);
  889. }
  890. return escapedDefs;
  891. }
  892. static StringArray getEscapedFlags (const StringArray& flags)
  893. {
  894. StringArray escaped;
  895. for (auto& flag : flags)
  896. escaped.add ("\"" + flag + "\"");
  897. return escaped;
  898. }
  899. //==============================================================================
  900. XmlElement* createManifestXML() const
  901. {
  902. XmlElement* manifest = new XmlElement ("manifest");
  903. manifest->setAttribute ("xmlns:android", "http://schemas.android.com/apk/res/android");
  904. manifest->setAttribute ("android:versionCode", androidVersionCode.get());
  905. manifest->setAttribute ("android:versionName", project.getVersionString());
  906. manifest->setAttribute ("package", getActivityClassPackage());
  907. if (! isLibrary())
  908. {
  909. XmlElement* screens = manifest->createNewChildElement ("supports-screens");
  910. screens->setAttribute ("android:smallScreens", "true");
  911. screens->setAttribute ("android:normalScreens", "true");
  912. screens->setAttribute ("android:largeScreens", "true");
  913. screens->setAttribute ("android:anyDensity", "true");
  914. }
  915. XmlElement* sdk = manifest->createNewChildElement ("uses-sdk");
  916. sdk->setAttribute ("android:minSdkVersion", androidMinimumSDK.get());
  917. sdk->setAttribute ("android:targetSdkVersion", androidMinimumSDK.get());
  918. {
  919. const StringArray permissions (getPermissionsRequired());
  920. for (int i = permissions.size(); --i >= 0;)
  921. manifest->createNewChildElement ("uses-permission")->setAttribute ("android:name", permissions[i]);
  922. }
  923. if (project.getModules().isModuleEnabled ("juce_opengl"))
  924. {
  925. XmlElement* feature = manifest->createNewChildElement ("uses-feature");
  926. feature->setAttribute ("android:glEsVersion", (androidMinimumSDK.get().getIntValue() >= 18 ? "0x00030000" : "0x00020000"));
  927. feature->setAttribute ("android:required", "true");
  928. }
  929. if (! isLibrary())
  930. {
  931. XmlElement* app = manifest->createNewChildElement ("application");
  932. app->setAttribute ("android:label", "@string/app_name");
  933. if (androidTheme.get().isNotEmpty())
  934. app->setAttribute ("android:theme", androidTheme.get());
  935. {
  936. ScopedPointer<Drawable> bigIcon (getBigIcon()), smallIcon (getSmallIcon());
  937. if (bigIcon != nullptr || smallIcon != nullptr)
  938. app->setAttribute ("android:icon", "@drawable/icon");
  939. }
  940. if (androidMinimumSDK.get().getIntValue() >= 11)
  941. app->setAttribute ("android:hardwareAccelerated", "false"); // (using the 2D acceleration slows down openGL)
  942. XmlElement* act = app->createNewChildElement ("activity");
  943. act->setAttribute ("android:name", getActivitySubClassName());
  944. act->setAttribute ("android:label", "@string/app_name");
  945. String configChanges ("keyboardHidden|orientation");
  946. if (androidMinimumSDK.get().getIntValue() >= 13)
  947. configChanges += "|screenSize";
  948. act->setAttribute ("android:configChanges", configChanges);
  949. act->setAttribute ("android:screenOrientation", androidScreenOrientation.get());
  950. XmlElement* intent = act->createNewChildElement ("intent-filter");
  951. intent->createNewChildElement ("action")->setAttribute ("android:name", "android.intent.action.MAIN");
  952. intent->createNewChildElement ("category")->setAttribute ("android:name", "android.intent.category.LAUNCHER");
  953. }
  954. return manifest;
  955. }
  956. StringArray getPermissionsRequired() const
  957. {
  958. StringArray s;
  959. s.addTokens (androidOtherPermissions.get(), ", ", "");
  960. if (androidInternetNeeded.get())
  961. s.add ("android.permission.INTERNET");
  962. if (androidMicNeeded.get())
  963. s.add ("android.permission.RECORD_AUDIO");
  964. if (androidBluetoothNeeded.get())
  965. {
  966. s.add ("android.permission.BLUETOOTH");
  967. s.add ("android.permission.BLUETOOTH_ADMIN");
  968. s.add ("android.permission.ACCESS_COARSE_LOCATION");
  969. }
  970. return getCleanedStringArray (s);
  971. }
  972. //==============================================================================
  973. bool isLibrary() const
  974. {
  975. return getProject().getProjectType().isDynamicLibrary()
  976. || getProject().getProjectType().isStaticLibrary();
  977. }
  978. static String toGradleList (const StringArray& array)
  979. {
  980. StringArray escapedArray;
  981. for (auto element : array)
  982. escapedArray.add ("\"" + element.replace ("\\", "\\\\").replace ("\"", "\\\"") + "\"");
  983. return escapedArray.joinIntoString (", ");
  984. }
  985. //==============================================================================
  986. Value sdkPath, ndkPath;
  987. const File AndroidExecutable;
  988. JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter)
  989. };
  990. ProjectExporter* createAndroidExporter (Project& p, const ValueTree& t)
  991. {
  992. return new AndroidProjectExporter (p, t);
  993. }
  994. ProjectExporter* createAndroidExporterForSetting (Project& p, const ValueTree& t)
  995. {
  996. return AndroidProjectExporter::createForSettings (p, t);
  997. }