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.

654 lines
29KB

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