Android: add Android Studio support, completely redone java part (#9066)
[oweals/minetest.git] / build / android / app / build.gradle
1 apply plugin: 'com.android.application'
2 android {
3         compileSdkVersion 29
4         buildToolsVersion '29.0.3'
5         ndkVersion '21.0.6113669'
6         defaultConfig {
7                 applicationId 'net.minetest.minetest'
8                 minSdkVersion 16
9                 //noinspection OldTargetApi
10                 targetSdkVersion 28 // Workaround for using `/sdcard` instead of the `data` patch for assets
11                 versionName "${versionMajor}.${versionMinor}.${versionPatch}"
12                 versionCode project.versionCode
13         }
14
15         Properties props = new Properties()
16         props.load(new FileInputStream(file('../local.properties')))
17
18         if (props.getProperty('keystore') != null) {
19                 signingConfigs {
20                         release {
21                                 storeFile file(props['keystore'])
22                                 storePassword props['keystore.password']
23                                 keyAlias props['key']
24                                 keyPassword props['key.password']
25                         }
26                 }
27
28                 buildTypes {
29                         release {
30                                 minifyEnabled true
31                                 signingConfig signingConfigs.release
32                         }
33                 }
34         }
35
36         // for multiple APKs
37         splits {
38                 abi {
39                         enable true
40                         reset()
41                         include 'armeabi-v7a', 'arm64-v8a'
42                 }
43         }
44
45         compileOptions {
46                 sourceCompatibility JavaVersion.VERSION_1_8
47                 targetCompatibility JavaVersion.VERSION_1_8
48         }
49 }
50
51 task prepareAssets() {
52         def assetsFolder = "build/assets"
53         def projRoot = "../../.."
54         def gameToCopy = "minetest_game"
55
56         copy {
57                 from "${projRoot}/minetest.conf.example", "${projRoot}/README.md" into assetsFolder
58         }
59         copy {
60                 from "${projRoot}/doc/lgpl-2.1.txt" into "${assetsFolder}"
61                 rename("lgpl-2.1.txt", "LICENSE.txt")
62         }
63         copy {
64                 from "${projRoot}/builtin" into "${assetsFolder}/builtin"
65         }
66         copy {
67                 from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders"
68         }
69         copy {
70                 from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts"
71         }
72         copy {
73                 from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}"
74         }
75         /*copy {
76                 // locales broken right now
77                 // ToDo: fix it!
78                 from "${projRoot}/po" into "${assetsFolder}/po"
79         }*/
80         copy {
81                 from "${projRoot}/textures" into "${assetsFolder}/textures"
82         }
83
84         task zipAssets(type: Zip) {
85                 archiveName "Minetest.zip"
86                 from "${assetsFolder}"
87                 destinationDir file("src/main/assets")
88         }
89 }
90
91 preBuild.dependsOn zipAssets
92
93 // Map for the version code that gives each ABI a value.
94 import com.android.build.OutputFile
95
96 def abiCodes = ['armeabi-v7a': 0, 'arm64-v8a': 1]
97 android.applicationVariants.all { variant ->
98         variant.outputs.each {
99                 output ->
100                         def abiName = output.getFilter(OutputFile.ABI)
101                         output.versionCodeOverride = abiCodes.get(abiName, 0) + variant.versionCode
102         }
103 }
104
105 dependencies {
106         implementation project(':native')
107         implementation 'androidx.appcompat:appcompat:1.1.0'
108 }