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.

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