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.

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