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.

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