build.gradle 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. apply plugin: 'com.android.application'
  2. android {
  3. compileSdkVersion 29
  4. sourceSets {
  5. main {
  6. manifest.srcFile 'AndroidManifest.xml'
  7. java.srcDirs = ['src/main/java']
  8. aidl.srcDirs = ['src/main/java']
  9. renderscript.srcDirs = ['src/main/java']
  10. res.srcDirs = ['res']
  11. assets.srcDirs = ['../assets']
  12. jniLibs.srcDirs = ['libs']
  13. }
  14. }
  15. packagingOptions {
  16. // Preventing from license violations (more or less):
  17. pickFirst 'META-INF/LICENSE.txt'
  18. pickFirst 'META-INF/LICENSE'
  19. pickFirst 'META-INF/license.txt'
  20. pickFirst 'META-INF/LGPL2.1'
  21. pickFirst 'META-INF/NOTICE.txt'
  22. pickFirst 'META-INF/NOTICE'
  23. pickFirst 'META-INF/notice.txt'
  24. // Excluding unnecessary meta-data:
  25. exclude 'META-INF/robovm/ios/robovm.xml'
  26. exclude 'META-INF/DEPENDENCIES.txt'
  27. exclude 'META-INF/DEPENDENCIES'
  28. exclude 'META-INF/dependencies.txt'
  29. }
  30. defaultConfig {
  31. applicationId 'com.example.packagename'
  32. minSdkVersion 19
  33. targetSdkVersion 29
  34. versionCode 1
  35. versionName "1.0"
  36. multiDexEnabled true
  37. }
  38. compileOptions {
  39. sourceCompatibility "8.0"
  40. targetCompatibility "8.0"
  41. coreLibraryDesugaringEnabled true
  42. }
  43. buildTypes {
  44. release {
  45. minifyEnabled false
  46. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  47. }
  48. }
  49. }
  50. repositories {
  51. // needed for AAPT2, may be needed for other tools
  52. google()
  53. }
  54. configurations { natives }
  55. dependencies {
  56. coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
  57. implementation project(':core')
  58. implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
  59. natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
  60. natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
  61. natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
  62. natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
  63. }
  64. // Called every time gradle gets executed, takes the native dependencies of
  65. // the natives configuration, and extracts them to the proper libs/ folders
  66. // so they get packed with the APK.
  67. task copyAndroidNatives() {
  68. doFirst {
  69. file("libs/armeabi/").mkdirs()
  70. file("libs/armeabi-v7a/").mkdirs()
  71. file("libs/arm64-v8a/").mkdirs()
  72. file("libs/x86_64/").mkdirs()
  73. file("libs/x86/").mkdirs()
  74. configurations.getByName("natives").copy().files.each { jar ->
  75. def outputDir = null
  76. if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
  77. if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
  78. if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
  79. if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
  80. if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
  81. if(outputDir != null) {
  82. copy {
  83. from zipTree(jar)
  84. into outputDir
  85. include "*.so"
  86. }
  87. }
  88. }
  89. }
  90. }
  91. tasks.whenTaskAdded { packageTask ->
  92. if (packageTask.name.contains("package")) {
  93. packageTask.dependsOn 'copyAndroidNatives'
  94. }
  95. }
  96. task run(type: Exec) {
  97. def path
  98. def localProperties = project.file("../local.properties")
  99. if (localProperties.exists()) {
  100. Properties properties = new Properties()
  101. localProperties.withInputStream { instr ->
  102. properties.load(instr)
  103. }
  104. def sdkDir = properties.getProperty('sdk.dir')
  105. if (sdkDir) {
  106. path = sdkDir
  107. } else {
  108. path = "$System.env.ANDROID_HOME"
  109. }
  110. } else {
  111. path = "$System.env.ANDROID_HOME"
  112. }
  113. def adb = path + "/platform-tools/adb"
  114. commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.example.packagename/com.example.packagename.AndroidLauncher'
  115. }
  116. eclipse.project.name = appName + "-android"