|
| 1 | +def localProperties = new Properties() |
| 2 | +def localPropertiesFile = rootProject.file('local.properties') |
| 3 | +if (localPropertiesFile.exists()) { |
| 4 | + localPropertiesFile.withReader('UTF-8') { reader -> |
| 5 | + localProperties.load(reader) |
| 6 | + } |
| 7 | +} |
| 8 | + |
| 9 | +// Load the build signing secrets from a local `keystore.properties` file. |
| 10 | +// TODO(YOU): Create release keys and a `keystore.properties` file. See |
| 11 | +// `example/README.md` for more info and `keystore.example.properties` for an |
| 12 | +// example. |
| 13 | +def keystorePropertiesFile = rootProject.file("keystore.properties") |
| 14 | +def keystoreProperties = new Properties() |
| 15 | +def configured = true |
| 16 | +try { |
| 17 | + keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) |
| 18 | +} catch (IOException e) { |
| 19 | + configured = false |
| 20 | + logger.error('Release signing information not found.') |
| 21 | +} |
| 22 | + |
| 23 | +project.ext { |
| 24 | + // TODO(YOU): Create release keys and a `keystore.properties` file. See |
| 25 | + // `example/README.md` for more info and `keystore.example.properties` for an |
| 26 | + // example. |
| 27 | + APP_ID = configured ? keystoreProperties['appId'] : "io.flutter.plugins.inapppurchaseexample.DEFAULT_DO_NOT_USE" |
| 28 | + KEYSTORE_STORE_FILE = configured ? rootProject.file(keystoreProperties['storeFile']) : null |
| 29 | + KEYSTORE_STORE_PASSWORD = keystoreProperties['storePassword'] |
| 30 | + KEYSTORE_KEY_ALIAS = keystoreProperties['keyAlias'] |
| 31 | + KEYSTORE_KEY_PASSWORD = keystoreProperties['keyPassword'] |
| 32 | + VERSION_CODE = configured ? keystoreProperties['versionCode'].toInteger() : 1 |
| 33 | + VERSION_NAME = configured ? keystoreProperties['versionName'] : "0.0.1" |
| 34 | +} |
| 35 | + |
| 36 | +if (project.APP_ID == "io.flutter.plugins.inapppurchaseexample.DEFAULT_DO_NOT_USE") { |
| 37 | + configured = false |
| 38 | + logger.error('Unique package name not set, defaulting to "io.flutter.plugins.inapppurchaseexample.DEFAULT_DO_NOT_USE".') |
| 39 | +} |
| 40 | + |
| 41 | +// Log a final error message if we're unable to create a release key signed |
| 42 | +// build for an app configured in the Play Developer Console. Apks built in this |
| 43 | +// condition won't be able to call any of the BillingClient APIs. |
| 44 | +if (!configured) { |
| 45 | + logger.error('The app could not be configured for release signing. In app purchases will not be testable. See `example/README.md` for more info and instructions.') |
| 46 | +} |
| 47 | + |
| 48 | +def flutterRoot = localProperties.getProperty('flutter.sdk') |
| 49 | +if (flutterRoot == null) { |
| 50 | + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") |
| 51 | +} |
| 52 | + |
| 53 | +apply plugin: 'com.android.application' |
| 54 | +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" |
| 55 | + |
| 56 | +android { |
| 57 | + signingConfigs { |
| 58 | + release { |
| 59 | + storeFile project.KEYSTORE_STORE_FILE |
| 60 | + storePassword project.KEYSTORE_STORE_PASSWORD |
| 61 | + keyAlias project.KEYSTORE_KEY_ALIAS |
| 62 | + keyPassword project.KEYSTORE_KEY_PASSWORD |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + compileSdkVersion 29 |
| 67 | + |
| 68 | + lintOptions { |
| 69 | + disable 'InvalidPackage' |
| 70 | + } |
| 71 | + |
| 72 | + defaultConfig { |
| 73 | + applicationId project.APP_ID |
| 74 | + minSdkVersion 16 |
| 75 | + targetSdkVersion 29 |
| 76 | + versionCode project.VERSION_CODE |
| 77 | + versionName project.VERSION_NAME |
| 78 | + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 79 | + } |
| 80 | + |
| 81 | + buildTypes { |
| 82 | + // Google Play Billing APIs only work with apps signed for production. |
| 83 | + debug { |
| 84 | + if (configured) { |
| 85 | + signingConfig signingConfigs.release |
| 86 | + } else { |
| 87 | + signingConfig signingConfigs.debug |
| 88 | + } |
| 89 | + } |
| 90 | + release { |
| 91 | + if (configured) { |
| 92 | + signingConfig signingConfigs.release |
| 93 | + } else { |
| 94 | + signingConfig signingConfigs.debug |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + testOptions { |
| 100 | + unitTests.returnDefaultValues = true |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +flutter { |
| 105 | + source '../..' |
| 106 | +} |
| 107 | + |
| 108 | +dependencies { |
| 109 | + implementation 'com.android.billingclient:billing:3.0.2' |
| 110 | + testImplementation 'junit:junit:4.12' |
| 111 | + testImplementation 'org.mockito:mockito-core:3.6.0' |
| 112 | + testImplementation 'org.json:json:20180813' |
| 113 | + androidTestImplementation 'androidx.test:runner:1.1.1' |
| 114 | + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' |
| 115 | +} |
0 commit comments