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.

640 lines
29KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. static const char* getNameAndroid() { return "Android Project"; }
  22. static const char* getValueTreeTypeName() { return "ANDROID"; }
  23. static AndroidProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  24. {
  25. if (settings.hasType (getValueTreeTypeName()))
  26. return new AndroidProjectExporter (project, settings);
  27. return nullptr;
  28. }
  29. //==============================================================================
  30. AndroidProjectExporter (Project& p, const ValueTree& t) : ProjectExporter (p, t)
  31. {
  32. name = getNameAndroid();
  33. if (getTargetLocationString().isEmpty())
  34. getTargetLocationValue() = getDefaultBuildsRootFolder() + "Android";
  35. if (getActivityClassPath().isEmpty())
  36. getActivityClassPathValue() = createDefaultClassName();
  37. if (getSDKPathString().isEmpty()) getSDKPathValue() = "${user.home}/SDKs/android-sdk";
  38. if (getNDKPathString().isEmpty()) getNDKPathValue() = "${user.home}/SDKs/android-ndk";
  39. if (getMinimumSDKVersionString().isEmpty())
  40. getMinimumSDKVersionValue() = 8;
  41. if (getInternetNeededValue().toString().isEmpty())
  42. getInternetNeededValue() = true;
  43. if (getKeyStoreValue().getValue().isVoid()) getKeyStoreValue() = "${user.home}/.android/debug.keystore";
  44. if (getKeyStorePassValue().getValue().isVoid()) getKeyStorePassValue() = "android";
  45. if (getKeyAliasValue().getValue().isVoid()) getKeyAliasValue() = "androiddebugkey";
  46. if (getKeyAliasPassValue().getValue().isVoid()) getKeyAliasPassValue() = "android";
  47. }
  48. //==============================================================================
  49. bool canLaunchProject() override { return false; }
  50. bool launchProject() override { return false; }
  51. bool isAndroid() const override { return true; }
  52. bool usesMMFiles() const override { return false; }
  53. bool canCopeWithDuplicateFiles() override { return false; }
  54. void createExporterProperties (PropertyListBuilder& props) override
  55. {
  56. props.add (new TextPropertyComponent (getActivityClassPathValue(), "Android Activity class name", 256, false),
  57. "The full java class name to use for the app's Activity class.");
  58. props.add (new TextPropertyComponent (getSDKPathValue(), "Android SDK Path", 1024, false),
  59. "The path to the Android SDK folder on the target build machine");
  60. props.add (new TextPropertyComponent (getNDKPathValue(), "Android NDK Path", 1024, false),
  61. "The path to the Android NDK folder on the target build machine");
  62. props.add (new TextPropertyComponent (getMinimumSDKVersionValue(), "Minimum SDK version", 32, false),
  63. "The number of the minimum version of the Android SDK that the app requires");
  64. props.add (new BooleanPropertyComponent (getCPP11EnabledValue(), "Enable C++11 features", "Enable the -std=c++0x flag"),
  65. "If enabled, this will set the -std=c++0x flag for the build.");
  66. props.add (new BooleanPropertyComponent (getInternetNeededValue(), "Internet Access", "Specify internet access permission in the manifest"),
  67. "If enabled, this will set the android.permission.INTERNET flag in the manifest.");
  68. props.add (new BooleanPropertyComponent (getAudioRecordNeededValue(), "Audio Input Required", "Specify audio record permission in the manifest"),
  69. "If enabled, this will set the android.permission.RECORD_AUDIO flag in the manifest.");
  70. props.add (new TextPropertyComponent (getOtherPermissionsValue(), "Custom permissions", 2048, false),
  71. "A space-separated list of other permission flags that should be added to the manifest.");
  72. props.add (new TextPropertyComponent (getKeyStoreValue(), "Key Signing: key.store", 2048, false),
  73. "The key.store value, used when signing the package.");
  74. props.add (new TextPropertyComponent (getKeyStorePassValue(), "Key Signing: key.store.password", 2048, false),
  75. "The key.store password, used when signing the package.");
  76. props.add (new TextPropertyComponent (getKeyAliasValue(), "Key Signing: key.alias", 2048, false),
  77. "The key.alias value, used when signing the package.");
  78. props.add (new TextPropertyComponent (getKeyAliasPassValue(), "Key Signing: key.alias.password", 2048, false),
  79. "The key.alias password, used when signing the package.");
  80. }
  81. Value getActivityClassPathValue() { return getSetting (Ids::androidActivityClass); }
  82. String getActivityClassPath() const { return settings [Ids::androidActivityClass]; }
  83. Value getSDKPathValue() { return getSetting (Ids::androidSDKPath); }
  84. String getSDKPathString() const { return settings [Ids::androidSDKPath]; }
  85. Value getNDKPathValue() { return getSetting (Ids::androidNDKPath); }
  86. String getNDKPathString() const { return settings [Ids::androidNDKPath]; }
  87. Value getKeyStoreValue() { return getSetting (Ids::androidKeyStore); }
  88. String getKeyStoreString() const { return settings [Ids::androidKeyStore]; }
  89. Value getKeyStorePassValue() { return getSetting (Ids::androidKeyStorePass); }
  90. String getKeyStorePassString() const { return settings [Ids::androidKeyStorePass]; }
  91. Value getKeyAliasValue() { return getSetting (Ids::androidKeyAlias); }
  92. String getKeyAliasString() const { return settings [Ids::androidKeyAlias]; }
  93. Value getKeyAliasPassValue() { return getSetting (Ids::androidKeyAliasPass); }
  94. String getKeyAliasPassString() const { return settings [Ids::androidKeyAliasPass]; }
  95. Value getInternetNeededValue() { return getSetting (Ids::androidInternetNeeded); }
  96. bool getInternetNeeded() const { return settings [Ids::androidInternetNeeded]; }
  97. Value getAudioRecordNeededValue() { return getSetting (Ids::androidMicNeeded); }
  98. bool getAudioRecordNeeded() const { return settings [Ids::androidMicNeeded]; }
  99. Value getMinimumSDKVersionValue() { return getSetting (Ids::androidMinimumSDK); }
  100. String getMinimumSDKVersionString() const { return settings [Ids::androidMinimumSDK]; }
  101. Value getOtherPermissionsValue() { return getSetting (Ids::androidOtherPermissions); }
  102. String getOtherPermissions() const { return settings [Ids::androidOtherPermissions]; }
  103. Value getCPP11EnabledValue() { return getSetting (Ids::androidCpp11); }
  104. bool isCPP11Enabled() const { return settings [Ids::androidCpp11]; }
  105. String createDefaultClassName() const
  106. {
  107. String s (project.getBundleIdentifier().toString().toLowerCase());
  108. if (s.length() > 5
  109. && s.containsChar ('.')
  110. && s.containsOnly ("abcdefghijklmnopqrstuvwxyz_.")
  111. && ! s.startsWithChar ('.'))
  112. {
  113. if (! s.endsWithChar ('.'))
  114. s << ".";
  115. }
  116. else
  117. {
  118. s = "com.yourcompany.";
  119. }
  120. return s + CodeHelpers::makeValidIdentifier (project.getProjectFilenameRoot(), false, true, false);
  121. }
  122. //==============================================================================
  123. void create (const OwnedArray<LibraryModule>& modules) const override
  124. {
  125. const File target (getTargetFolder());
  126. const File jniFolder (target.getChildFile ("jni"));
  127. copyActivityJavaFiles (modules);
  128. createDirectoryOrThrow (jniFolder);
  129. createDirectoryOrThrow (target.getChildFile ("res").getChildFile ("values"));
  130. createDirectoryOrThrow (target.getChildFile ("libs"));
  131. createDirectoryOrThrow (target.getChildFile ("bin"));
  132. {
  133. ScopedPointer<XmlElement> manifest (createManifestXML());
  134. writeXmlOrThrow (*manifest, target.getChildFile ("AndroidManifest.xml"), "utf-8", 100, true);
  135. }
  136. writeApplicationMk (jniFolder.getChildFile ("Application.mk"));
  137. writeAndroidMk (jniFolder.getChildFile ("Android.mk"));
  138. {
  139. ScopedPointer<XmlElement> antBuildXml (createAntBuildXML());
  140. writeXmlOrThrow (*antBuildXml, target.getChildFile ("build.xml"), "UTF-8", 100);
  141. }
  142. writeProjectPropertiesFile (target.getChildFile ("project.properties"));
  143. writeLocalPropertiesFile (target.getChildFile ("local.properties"));
  144. writeStringsFile (target.getChildFile ("res/values/strings.xml"));
  145. const Image bigIcon (getBigIcon());
  146. const Image smallIcon (getSmallIcon());
  147. if (bigIcon.isValid() && smallIcon.isValid())
  148. {
  149. const int step = jmax (bigIcon.getWidth(), bigIcon.getHeight()) / 8;
  150. writeIcon (target.getChildFile ("res/drawable-xhdpi/icon.png"), getBestIconForSize (step * 8, false));
  151. writeIcon (target.getChildFile ("res/drawable-hdpi/icon.png"), getBestIconForSize (step * 6, false));
  152. writeIcon (target.getChildFile ("res/drawable-mdpi/icon.png"), getBestIconForSize (step * 4, false));
  153. writeIcon (target.getChildFile ("res/drawable-ldpi/icon.png"), getBestIconForSize (step * 3, false));
  154. }
  155. else
  156. {
  157. writeIcon (target.getChildFile ("res/drawable-mdpi/icon.png"), bigIcon.isValid() ? bigIcon : smallIcon);
  158. }
  159. }
  160. protected:
  161. //==============================================================================
  162. class AndroidBuildConfiguration : public BuildConfiguration
  163. {
  164. public:
  165. AndroidBuildConfiguration (Project& p, const ValueTree& settings)
  166. : BuildConfiguration (p, settings)
  167. {
  168. if (getArchitectures().isEmpty())
  169. getArchitecturesValue() = "armeabi armeabi-v7a";
  170. }
  171. Value getArchitecturesValue() { return getValue (Ids::androidArchitectures); }
  172. String getArchitectures() const { return config [Ids::androidArchitectures]; }
  173. void createConfigProperties (PropertyListBuilder& props)
  174. {
  175. props.add (new TextPropertyComponent (getArchitecturesValue(), "Architectures", 256, false),
  176. "A list of the ARM architectures to build (for a fat binary).");
  177. }
  178. };
  179. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const
  180. {
  181. return new AndroidBuildConfiguration (project, v);
  182. }
  183. private:
  184. //==============================================================================
  185. XmlElement* createManifestXML() const
  186. {
  187. XmlElement* manifest = new XmlElement ("manifest");
  188. manifest->setAttribute ("xmlns:android", "http://schemas.android.com/apk/res/android");
  189. manifest->setAttribute ("android:versionCode", "1");
  190. manifest->setAttribute ("android:versionName", "1.0");
  191. manifest->setAttribute ("package", getActivityClassPackage());
  192. XmlElement* screens = manifest->createNewChildElement ("supports-screens");
  193. screens->setAttribute ("android:smallScreens", "true");
  194. screens->setAttribute ("android:normalScreens", "true");
  195. screens->setAttribute ("android:largeScreens", "true");
  196. //screens->setAttribute ("android:xlargeScreens", "true");
  197. screens->setAttribute ("android:anyDensity", "true");
  198. XmlElement* sdk = manifest->createNewChildElement ("uses-sdk");
  199. sdk->setAttribute ("android:minSdkVersion", getMinimumSDKVersionString());
  200. sdk->setAttribute ("android:targetSdkVersion", "11");
  201. {
  202. const StringArray permissions (getPermissionsRequired());
  203. for (int i = permissions.size(); --i >= 0;)
  204. manifest->createNewChildElement ("uses-permission")->setAttribute ("android:name", permissions[i]);
  205. }
  206. if (project.isModuleEnabled ("juce_opengl"))
  207. {
  208. XmlElement* feature = manifest->createNewChildElement ("uses-feature");
  209. feature->setAttribute ("android:glEsVersion", "0x00020000");
  210. feature->setAttribute ("android:required", "true");
  211. }
  212. XmlElement* app = manifest->createNewChildElement ("application");
  213. app->setAttribute ("android:label", "@string/app_name");
  214. app->setAttribute ("android:icon", "@drawable/icon");
  215. if (getMinimumSDKVersionString().getIntValue() >= 11)
  216. app->setAttribute ("android:hardwareAccelerated", "false"); // (using the 2D acceleration slows down openGL)
  217. XmlElement* act = app->createNewChildElement ("activity");
  218. act->setAttribute ("android:name", getActivityName());
  219. act->setAttribute ("android:label", "@string/app_name");
  220. act->setAttribute ("android:configChanges", "keyboardHidden|orientation");
  221. XmlElement* intent = act->createNewChildElement ("intent-filter");
  222. intent->createNewChildElement ("action")->setAttribute ("android:name", "android.intent.action.MAIN");
  223. intent->createNewChildElement ("category")->setAttribute ("android:name", "android.intent.category.LAUNCHER");
  224. return manifest;
  225. }
  226. StringArray getPermissionsRequired() const
  227. {
  228. StringArray s;
  229. s.addTokens (getOtherPermissions(), ", ", "");
  230. if (getInternetNeeded()) s.add ("android.permission.INTERNET");
  231. if (getAudioRecordNeeded()) s.add ("android.permission.RECORD_AUDIO");
  232. s.trim();
  233. s.removeDuplicates (false);
  234. return s;
  235. }
  236. //==============================================================================
  237. void findAllFilesToCompile (const Project::Item& projectItem, Array<RelativePath>& results) const
  238. {
  239. if (projectItem.isGroup())
  240. {
  241. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  242. findAllFilesToCompile (projectItem.getChild(i), results);
  243. }
  244. else
  245. {
  246. if (projectItem.shouldBeCompiled())
  247. results.add (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder));
  248. }
  249. }
  250. //==============================================================================
  251. String getActivityName() const
  252. {
  253. return getActivityClassPath().fromLastOccurrenceOf (".", false, false);
  254. }
  255. String getActivityClassPackage() const
  256. {
  257. return getActivityClassPath().upToLastOccurrenceOf (".", false, false);
  258. }
  259. String getJNIActivityClassName() const
  260. {
  261. return getActivityClassPath().replaceCharacter ('.', '/');
  262. }
  263. static LibraryModule* getCoreModule (const OwnedArray<LibraryModule>& modules)
  264. {
  265. for (int i = modules.size(); --i >= 0;)
  266. if (modules.getUnchecked(i)->getID() == "juce_core")
  267. return modules.getUnchecked(i);
  268. return nullptr;
  269. }
  270. void copyActivityJavaFiles (const OwnedArray<LibraryModule>& modules) const
  271. {
  272. const String className (getActivityName());
  273. const String package (getActivityClassPackage());
  274. String path (package.replaceCharacter ('.', File::separator));
  275. if (path.isEmpty() || className.isEmpty())
  276. throw SaveError ("Invalid Android Activity class name: " + getActivityClassPath());
  277. const File classFolder (getTargetFolder().getChildFile ("src")
  278. .getChildFile (path));
  279. createDirectoryOrThrow (classFolder);
  280. LibraryModule* const coreModule = getCoreModule (modules);
  281. if (coreModule == nullptr)
  282. throw SaveError ("To build an Android app, the juce_core module must be included in your project!");
  283. File javaDestFile (classFolder.getChildFile (className + ".java"));
  284. File javaSourceFile (coreModule->getFolder().getChildFile ("native")
  285. .getChildFile ("java")
  286. .getChildFile ("JuceAppActivity.java"));
  287. MemoryOutputStream newFile;
  288. newFile << javaSourceFile.loadFileAsString()
  289. .replace ("JuceAppActivity", className)
  290. .replace ("package com.juce;", "package " + package + ";");
  291. overwriteFileIfDifferentOrThrow (javaDestFile, newFile);
  292. }
  293. void writeApplicationMk (const File& file) const
  294. {
  295. MemoryOutputStream mo;
  296. mo << "# Automatically generated makefile, created by the Introjucer" << newLine
  297. << "# Don't edit this file! Your changes will be overwritten when you re-save the Introjucer project!" << newLine
  298. << newLine
  299. << "APP_STL := gnustl_static" << newLine
  300. << "APP_CPPFLAGS += -fsigned-char -fexceptions -frtti -Wno-psabi" << newLine
  301. << "APP_PLATFORM := " << getAppPlatform() << newLine;
  302. overwriteFileIfDifferentOrThrow (file, mo);
  303. }
  304. void writeAndroidMk (const File& file) const
  305. {
  306. Array<RelativePath> files;
  307. for (int i = 0; i < getAllGroups().size(); ++i)
  308. findAllFilesToCompile (getAllGroups().getReference(i), files);
  309. MemoryOutputStream mo;
  310. writeAndroidMk (mo, files);
  311. overwriteFileIfDifferentOrThrow (file, mo);
  312. }
  313. void writeAndroidMk (OutputStream& out, const Array<RelativePath>& files) const
  314. {
  315. out << "# Automatically generated makefile, created by the Introjucer" << newLine
  316. << "# Don't edit this file! Your changes will be overwritten when you re-save the Introjucer project!" << newLine
  317. << newLine
  318. << "LOCAL_PATH := $(call my-dir)" << newLine
  319. << newLine
  320. << "include $(CLEAR_VARS)" << newLine
  321. << newLine
  322. << "LOCAL_ARM_MODE := arm" << newLine
  323. << "LOCAL_MODULE := juce_jni" << newLine
  324. << "LOCAL_SRC_FILES := \\" << newLine;
  325. for (int i = 0; i < files.size(); ++i)
  326. out << " ../" << escapeSpaces (files.getReference(i).toUnixStyle()) << "\\" << newLine;
  327. String debugSettings, releaseSettings;
  328. out << newLine
  329. << "ifeq ($(CONFIG),Debug)" << newLine;
  330. writeConfigSettings (out, true);
  331. out << "else" << newLine;
  332. writeConfigSettings (out, false);
  333. out << "endif" << newLine
  334. << newLine
  335. << "include $(BUILD_SHARED_LIBRARY)" << newLine;
  336. }
  337. void writeConfigSettings (OutputStream& out, bool forDebug) const
  338. {
  339. for (ConstConfigIterator config (*this); config.next();)
  340. {
  341. if (config->isDebug() == forDebug)
  342. {
  343. const AndroidBuildConfiguration& androidConfig = dynamic_cast <const AndroidBuildConfiguration&> (*config);
  344. String cppFlags;
  345. cppFlags << createCPPFlags (androidConfig)
  346. << (" " + replacePreprocessorTokens (androidConfig, getExtraCompilerFlagsString()).trim()).trimEnd()
  347. << newLine
  348. << getLDLIBS (androidConfig).trimEnd()
  349. << newLine;
  350. out << " LOCAL_CPPFLAGS += " << cppFlags;
  351. out << " LOCAL_CFLAGS += " << cppFlags;
  352. break;
  353. }
  354. }
  355. }
  356. String getLDLIBS (const AndroidBuildConfiguration& config) const
  357. {
  358. return " LOCAL_LDLIBS :=" + config.getGCCLibraryPathFlags()
  359. + " -llog -lGLESv2 " + getExternalLibraryFlags (config)
  360. + " " + replacePreprocessorTokens (config, getExtraLinkerFlagsString());
  361. }
  362. String createIncludePathFlags (const BuildConfiguration& config) const
  363. {
  364. String flags;
  365. StringArray searchPaths (extraSearchPaths);
  366. searchPaths.addArray (config.getHeaderSearchPaths());
  367. searchPaths.removeDuplicates (false);
  368. for (int i = 0; i < searchPaths.size(); ++i)
  369. flags << " -I " << FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i])).quoted();
  370. return flags;
  371. }
  372. String createCPPFlags (const BuildConfiguration& config) const
  373. {
  374. StringPairArray defines;
  375. defines.set ("JUCE_ANDROID", "1");
  376. defines.set ("JUCE_ANDROID_API_VERSION", getMinimumSDKVersionString());
  377. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSNAME", getJNIActivityClassName().replaceCharacter ('/', '_'));
  378. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSPATH", "\\\"" + getJNIActivityClassName() + "\\\"");
  379. String flags ("-fsigned-char -fexceptions -frtti");
  380. if (config.isDebug())
  381. {
  382. flags << " -g";
  383. defines.set ("DEBUG", "1");
  384. defines.set ("_DEBUG", "1");
  385. }
  386. else
  387. {
  388. defines.set ("NDEBUG", "1");
  389. }
  390. flags << createIncludePathFlags (config)
  391. << " -O" << config.getGCCOptimisationFlag();
  392. if (isCPP11Enabled())
  393. flags << " -std=c++0x";
  394. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  395. return flags + createGCCPreprocessorFlags (defines);
  396. }
  397. //==============================================================================
  398. XmlElement* createAntBuildXML() const
  399. {
  400. XmlElement* proj = new XmlElement ("project");
  401. proj->setAttribute ("name", projectName);
  402. proj->setAttribute ("default", "debug");
  403. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "local.properties");
  404. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "project.properties");
  405. {
  406. XmlElement* target = proj->createNewChildElement ("target");
  407. target->setAttribute ("name", "clean");
  408. XmlElement* executable = target->createNewChildElement ("exec");
  409. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  410. executable->setAttribute ("dir", "${basedir}");
  411. executable->setAttribute ("failonerror", "true");
  412. executable->createNewChildElement ("arg")->setAttribute ("value", "clean");
  413. }
  414. {
  415. XmlElement* target = proj->createNewChildElement ("target");
  416. target->setAttribute ("name", "-pre-build");
  417. addDebugConditionClause (target, "makefileConfig", "Debug", "Release");
  418. addDebugConditionClause (target, "ndkDebugValue", "NDK_DEBUG=1", "NDK_DEBUG=0");
  419. String debugABIs, releaseABIs;
  420. for (ConstConfigIterator config (*this); config.next();)
  421. {
  422. const AndroidBuildConfiguration& androidConfig = dynamic_cast <const AndroidBuildConfiguration&> (*config);
  423. if (config->isDebug())
  424. debugABIs = androidConfig.getArchitectures();
  425. else
  426. releaseABIs = androidConfig.getArchitectures();
  427. }
  428. addDebugConditionClause (target, "app_abis", debugABIs, releaseABIs);
  429. XmlElement* executable = target->createNewChildElement ("exec");
  430. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  431. executable->setAttribute ("dir", "${basedir}");
  432. executable->setAttribute ("failonerror", "true");
  433. executable->createNewChildElement ("arg")->setAttribute ("value", "--jobs=2");
  434. executable->createNewChildElement ("arg")->setAttribute ("value", "CONFIG=${makefileConfig}");
  435. executable->createNewChildElement ("arg")->setAttribute ("value", "${ndkDebugValue}");
  436. executable->createNewChildElement ("arg")->setAttribute ("value", "APP_ABI=${app_abis}");
  437. target->createNewChildElement ("delete")->setAttribute ("file", "${out.final.file}");
  438. target->createNewChildElement ("delete")->setAttribute ("file", "${out.packaged.file}");
  439. }
  440. proj->createNewChildElement ("import")->setAttribute ("file", "${sdk.dir}/tools/ant/build.xml");
  441. return proj;
  442. }
  443. void addDebugConditionClause (XmlElement* target, const String& property,
  444. const String& debugValue, const String& releaseValue) const
  445. {
  446. XmlElement* condition = target->createNewChildElement ("condition");
  447. condition->setAttribute ("property", property);
  448. condition->setAttribute ("value", debugValue);
  449. condition->setAttribute ("else", releaseValue);
  450. XmlElement* equals = condition->createNewChildElement ("equals");
  451. equals->setAttribute ("arg1", "${ant.project.invoked-targets}");
  452. equals->setAttribute ("arg2", "debug");
  453. }
  454. String getAppPlatform() const
  455. {
  456. int ndkVersion = getMinimumSDKVersionString().getIntValue();
  457. if (ndkVersion == 9)
  458. ndkVersion = 10; // (doesn't seem to be a version '9')
  459. return "android-" + String (ndkVersion);
  460. }
  461. void writeProjectPropertiesFile (const File& file) const
  462. {
  463. MemoryOutputStream mo;
  464. mo << "# This file is used to override default values used by the Ant build system." << newLine
  465. << "# It is automatically generated - DO NOT EDIT IT or your changes will be lost!." << newLine
  466. << newLine
  467. << "target=" << getAppPlatform() << newLine
  468. << newLine;
  469. overwriteFileIfDifferentOrThrow (file, mo);
  470. }
  471. void writeLocalPropertiesFile (const File& file) const
  472. {
  473. MemoryOutputStream mo;
  474. mo << "# This file is used to override default values used by the Ant build system." << newLine
  475. << "# It is automatically generated by the Introjucer - DO NOT EDIT IT or your changes will be lost!." << newLine
  476. << newLine
  477. << "sdk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getSDKPathString())) << newLine
  478. << "ndk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getNDKPathString())) << newLine
  479. << "key.store=" << getKeyStoreString() << newLine
  480. << "key.alias=" << getKeyAliasString() << newLine
  481. << "key.store.password=" << getKeyStorePassString() << newLine
  482. << "key.alias.password=" << getKeyAliasPassString() << newLine
  483. << newLine;
  484. overwriteFileIfDifferentOrThrow (file, mo);
  485. }
  486. void writeIcon (const File& file, const Image& im) const
  487. {
  488. if (im.isValid())
  489. {
  490. createDirectoryOrThrow (file.getParentDirectory());
  491. PNGImageFormat png;
  492. MemoryOutputStream mo;
  493. if (! png.writeImageToStream (im, mo))
  494. throw SaveError ("Can't generate Android icon file");
  495. overwriteFileIfDifferentOrThrow (file, mo);
  496. }
  497. }
  498. void writeStringsFile (const File& file) const
  499. {
  500. XmlElement strings ("resources");
  501. XmlElement* resourceName = strings.createNewChildElement ("string");
  502. resourceName->setAttribute ("name", "app_name");
  503. resourceName->addTextElement (projectName);
  504. writeXmlOrThrow (strings, file, "utf-8", 100);
  505. }
  506. //==============================================================================
  507. JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter)
  508. };