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.

652 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. manifest->createNewChildElement ("uses-sdk")->setAttribute ("android:minSdkVersion", getMinimumSDKVersionString());
  203. {
  204. const StringArray permissions (getPermissionsRequired());
  205. for (int i = permissions.size(); --i >= 0;)
  206. manifest->createNewChildElement ("uses-permission")->setAttribute ("android:name", permissions[i]);
  207. }
  208. if (project.isModuleEnabled ("juce_opengl"))
  209. {
  210. XmlElement* feature = manifest->createNewChildElement ("uses-feature");
  211. feature->setAttribute ("android:glEsVersion", "0x00020000");
  212. feature->setAttribute ("android:required", "true");
  213. }
  214. XmlElement* app = manifest->createNewChildElement ("application");
  215. app->setAttribute ("android:label", "@string/app_name");
  216. app->setAttribute ("android:icon", "@drawable/icon");
  217. app->setAttribute ("android:hardwareAccelerated", "false"); // (using the 2D acceleration slows down openGL)
  218. XmlElement* act = app->createNewChildElement ("activity");
  219. act->setAttribute ("android:name", getActivityName());
  220. act->setAttribute ("android:label", "@string/app_name");
  221. act->setAttribute ("android:configChanges", "keyboardHidden|orientation");
  222. XmlElement* intent = act->createNewChildElement ("intent-filter");
  223. intent->createNewChildElement ("action")->setAttribute ("android:name", "android.intent.action.MAIN");
  224. intent->createNewChildElement ("category")->setAttribute ("android:name", "android.intent.category.LAUNCHER");
  225. return manifest;
  226. }
  227. StringArray getPermissionsRequired() const
  228. {
  229. StringArray s;
  230. s.addTokens (getOtherPermissions(), ", ", "");
  231. if (getInternetNeeded()) s.add ("android.permission.INTERNET");
  232. if (getAudioRecordNeeded()) s.add ("android.permission.RECORD_AUDIO");
  233. s.trim();
  234. s.removeDuplicates (false);
  235. return s;
  236. }
  237. //==============================================================================
  238. void findAllFilesToCompile (const Project::Item& projectItem, Array<RelativePath>& results) const
  239. {
  240. if (projectItem.isGroup())
  241. {
  242. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  243. findAllFilesToCompile (projectItem.getChild(i), results);
  244. }
  245. else
  246. {
  247. if (projectItem.shouldBeCompiled())
  248. results.add (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder));
  249. }
  250. }
  251. //==============================================================================
  252. String getActivityName() const
  253. {
  254. return getActivityClassPath().fromLastOccurrenceOf (".", false, false);
  255. }
  256. String getActivityClassPackage() const
  257. {
  258. return getActivityClassPath().upToLastOccurrenceOf (".", false, false);
  259. }
  260. String getJNIActivityClassName() const
  261. {
  262. return getActivityClassPath().replaceCharacter ('.', '/');
  263. }
  264. static LibraryModule* getCoreModule (const OwnedArray<LibraryModule>& modules)
  265. {
  266. for (int i = modules.size(); --i >= 0;)
  267. if (modules.getUnchecked(i)->getID() == "juce_core")
  268. return modules.getUnchecked(i);
  269. return nullptr;
  270. }
  271. void copyActivityJavaFiles (const OwnedArray<LibraryModule>& modules) const
  272. {
  273. const String className (getActivityName());
  274. const String package (getActivityClassPackage());
  275. String path (package.replaceCharacter ('.', File::separator));
  276. if (path.isEmpty() || className.isEmpty())
  277. throw SaveError ("Invalid Android Activity class name: " + getActivityClassPath());
  278. const File classFolder (getTargetFolder().getChildFile ("src")
  279. .getChildFile (path));
  280. createDirectoryOrThrow (classFolder);
  281. LibraryModule* const coreModule = getCoreModule (modules);
  282. if (coreModule == nullptr)
  283. throw SaveError ("To build an Android app, the juce_core module must be included in your project!");
  284. File javaDestFile (classFolder.getChildFile (className + ".java"));
  285. File javaSourceFile (coreModule->getFolder().getChildFile ("native")
  286. .getChildFile ("java")
  287. .getChildFile ("JuceAppActivity.java"));
  288. MemoryOutputStream newFile;
  289. newFile << javaSourceFile.loadFileAsString()
  290. .replace ("JuceAppActivity", className)
  291. .replace ("package com.juce;", "package " + package + ";");
  292. overwriteFileIfDifferentOrThrow (javaDestFile, newFile);
  293. }
  294. void writeApplicationMk (const File& file) const
  295. {
  296. MemoryOutputStream mo;
  297. mo << "# Automatically generated makefile, created by the Introjucer" << newLine
  298. << "# Don't edit this file! Your changes will be overwritten when you re-save the Introjucer project!" << newLine
  299. << newLine
  300. << "APP_STL := gnustl_static" << newLine
  301. << "APP_CPPFLAGS += -fsigned-char -fexceptions -frtti -Wno-psabi" << newLine
  302. << "APP_PLATFORM := " << getAppPlatform() << newLine;
  303. overwriteFileIfDifferentOrThrow (file, mo);
  304. }
  305. void writeAndroidMk (const File& file) const
  306. {
  307. Array<RelativePath> files;
  308. for (int i = 0; i < getAllGroups().size(); ++i)
  309. findAllFilesToCompile (getAllGroups().getReference(i), files);
  310. MemoryOutputStream mo;
  311. writeAndroidMk (mo, files);
  312. overwriteFileIfDifferentOrThrow (file, mo);
  313. }
  314. void writeAndroidMk (OutputStream& out, const Array<RelativePath>& files) const
  315. {
  316. out << "# Automatically generated makefile, created by the Introjucer" << newLine
  317. << "# Don't edit this file! Your changes will be overwritten when you re-save the Introjucer project!" << newLine
  318. << newLine
  319. << "LOCAL_PATH := $(call my-dir)" << newLine
  320. << newLine
  321. << "include $(CLEAR_VARS)" << newLine
  322. << 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. out << " LOCAL_CPPFLAGS += " << createCPPFlags (androidConfig)
  345. << (" " + replacePreprocessorTokens (androidConfig, getExtraCompilerFlagsString()).trim()).trimEnd()
  346. << newLine
  347. << getDynamicLibs (androidConfig);
  348. break;
  349. }
  350. }
  351. }
  352. String getDynamicLibs (const AndroidBuildConfiguration& config) const
  353. {
  354. String flags (" LOCAL_LDLIBS :=");
  355. flags << config.getGCCLibraryPathFlags();
  356. {
  357. StringArray libs;
  358. libs.add ("log");
  359. libs.add ("GLESv2");
  360. for (int i = 0; i < libs.size(); ++i)
  361. flags << " -l" << libs[i];
  362. }
  363. return flags + newLine;
  364. }
  365. String createIncludePathFlags (const BuildConfiguration& config) const
  366. {
  367. String flags;
  368. StringArray searchPaths (extraSearchPaths);
  369. searchPaths.addArray (config.getHeaderSearchPaths());
  370. searchPaths.removeDuplicates (false);
  371. for (int i = 0; i < searchPaths.size(); ++i)
  372. flags << " -I " << FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i])).quoted();
  373. return flags;
  374. }
  375. String createCPPFlags (const BuildConfiguration& config) const
  376. {
  377. StringPairArray defines;
  378. defines.set ("JUCE_ANDROID", "1");
  379. defines.set ("JUCE_ANDROID_API_VERSION", getMinimumSDKVersionString());
  380. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSNAME", getJNIActivityClassName().replaceCharacter ('/', '_'));
  381. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSPATH", "\\\"" + getJNIActivityClassName() + "\\\"");
  382. String flags ("-fsigned-char -fexceptions -frtti");
  383. if (config.isDebug())
  384. {
  385. flags << " -g";
  386. defines.set ("DEBUG", "1");
  387. defines.set ("_DEBUG", "1");
  388. }
  389. else
  390. {
  391. defines.set ("NDEBUG", "1");
  392. }
  393. flags << createIncludePathFlags (config)
  394. << " -O" << config.getGCCOptimisationFlag();
  395. if (isCPP11Enabled())
  396. flags << " -std=c++0x";
  397. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  398. return flags + createGCCPreprocessorFlags (defines);
  399. }
  400. //==============================================================================
  401. XmlElement* createAntBuildXML() const
  402. {
  403. XmlElement* proj = new XmlElement ("project");
  404. proj->setAttribute ("name", projectName);
  405. proj->setAttribute ("default", "debug");
  406. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "local.properties");
  407. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "project.properties");
  408. {
  409. XmlElement* target = proj->createNewChildElement ("target");
  410. target->setAttribute ("name", "clean");
  411. XmlElement* executable = target->createNewChildElement ("exec");
  412. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  413. executable->setAttribute ("dir", "${basedir}");
  414. executable->setAttribute ("failonerror", "true");
  415. executable->createNewChildElement ("arg")->setAttribute ("value", "clean");
  416. }
  417. {
  418. XmlElement* target = proj->createNewChildElement ("target");
  419. target->setAttribute ("name", "-pre-build");
  420. addDebugConditionClause (target, "makefileConfig", "Debug", "Release");
  421. addDebugConditionClause (target, "ndkDebugValue", "NDK_DEBUG=1", "NDK_DEBUG=0");
  422. String debugABIs, releaseABIs;
  423. for (ConstConfigIterator config (*this); config.next();)
  424. {
  425. const AndroidBuildConfiguration& androidConfig = dynamic_cast <const AndroidBuildConfiguration&> (*config);
  426. if (config->isDebug())
  427. debugABIs = androidConfig.getArchitectures();
  428. else
  429. releaseABIs = androidConfig.getArchitectures();
  430. }
  431. addDebugConditionClause (target, "app_abis", debugABIs, releaseABIs);
  432. XmlElement* executable = target->createNewChildElement ("exec");
  433. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  434. executable->setAttribute ("dir", "${basedir}");
  435. executable->setAttribute ("failonerror", "true");
  436. executable->createNewChildElement ("arg")->setAttribute ("value", "--jobs=2");
  437. executable->createNewChildElement ("arg")->setAttribute ("value", "CONFIG=${makefileConfig}");
  438. executable->createNewChildElement ("arg")->setAttribute ("value", "${ndkDebugValue}");
  439. executable->createNewChildElement ("arg")->setAttribute ("value", "APP_ABI=${app_abis}");
  440. target->createNewChildElement ("delete")->setAttribute ("file", "${out.final.file}");
  441. target->createNewChildElement ("delete")->setAttribute ("file", "${out.packaged.file}");
  442. }
  443. proj->createNewChildElement ("import")->setAttribute ("file", "${sdk.dir}/tools/ant/build.xml");
  444. return proj;
  445. }
  446. void addDebugConditionClause (XmlElement* target, const String& property,
  447. const String& debugValue, const String& releaseValue) const
  448. {
  449. XmlElement* condition = target->createNewChildElement ("condition");
  450. condition->setAttribute ("property", property);
  451. condition->setAttribute ("value", debugValue);
  452. condition->setAttribute ("else", releaseValue);
  453. XmlElement* equals = condition->createNewChildElement ("equals");
  454. equals->setAttribute ("arg1", "${ant.project.invoked-targets}");
  455. equals->setAttribute ("arg2", "debug");
  456. }
  457. String getAppPlatform() const
  458. {
  459. int ndkVersion = getMinimumSDKVersionString().getIntValue();
  460. if (ndkVersion == 9)
  461. ndkVersion = 10; // (doesn't seem to be a version '9')
  462. return "android-" + String (ndkVersion);
  463. }
  464. void writeProjectPropertiesFile (const File& file) const
  465. {
  466. MemoryOutputStream mo;
  467. mo << "# This file is used to override default values used by the Ant build system." << newLine
  468. << "# It is automatically generated - DO NOT EDIT IT or your changes will be lost!." << newLine
  469. << newLine
  470. << "target=" << getAppPlatform() << newLine
  471. << newLine;
  472. overwriteFileIfDifferentOrThrow (file, mo);
  473. }
  474. void writeLocalPropertiesFile (const File& file) const
  475. {
  476. MemoryOutputStream mo;
  477. mo << "# This file is used to override default values used by the Ant build system." << newLine
  478. << "# It is automatically generated by the Introjucer - DO NOT EDIT IT or your changes will be lost!." << newLine
  479. << newLine
  480. << "sdk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getSDKPathString())) << newLine
  481. << "ndk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getNDKPathString())) << newLine
  482. << "key.store=" << getKeyStoreString() << newLine
  483. << "key.alias=" << getKeyAliasString() << newLine
  484. << "key.store.password=" << getKeyStorePassString() << newLine
  485. << "key.alias.password=" << getKeyAliasPassString() << newLine
  486. << newLine;
  487. overwriteFileIfDifferentOrThrow (file, mo);
  488. }
  489. void writeIcon (const File& file, const Image& im) const
  490. {
  491. if (im.isValid())
  492. {
  493. createDirectoryOrThrow (file.getParentDirectory());
  494. PNGImageFormat png;
  495. MemoryOutputStream mo;
  496. if (! png.writeImageToStream (im, mo))
  497. throw SaveError ("Can't generate Android icon file");
  498. overwriteFileIfDifferentOrThrow (file, mo);
  499. }
  500. }
  501. void writeStringsFile (const File& file) const
  502. {
  503. XmlElement strings ("resources");
  504. XmlElement* name = strings.createNewChildElement ("string");
  505. name->setAttribute ("name", "app_name");
  506. name->addTextElement (projectName);
  507. writeXmlOrThrow (strings, file, "utf-8", 100);
  508. }
  509. //==============================================================================
  510. JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter);
  511. };
  512. #endif // __JUCER_PROJECTEXPORT_ANDROID_JUCEHEADER__