Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/in_app_purchase/in_app_purchase/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ below.
- `subscription_silver`: A lower level subscription.
- `subscription_gold`: A higher level subscription.

Make sure that all of the products are set to `ACTIVE`.
Make sure that all the products are set to `ACTIVE`.

4. Update `APP_ID` in `example/android/app/build.gradle` to match your package
ID in the PDC.
Expand Down
58 changes: 58 additions & 0 deletions packages/in_app_purchase/in_app_purchase_android/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# In App Purchase Example

Demonstrates how to use the In App Purchase Android (IAP) Plugin.

## Getting Started

### Preparation

There's a significant amount of setup required for testing in-app purchases
successfully, including registering new app IDs and store entries to use for
testing in the Play Developer Console. Google Play requires developers to
configure an app with in-app items for purchase to call their in-app-purchase
APIs. The Google Play Store has extensive documentation on how to do this, and
we've also included a high level guide below.

* [Google Play Billing Overview](https://developer.android.com/google/play/billing/billing_overview)

### Android

1. Create a new app in the [Play Developer
Console](https://play.google.com/apps/publish/) (PDC).

2. Sign up for a merchant's account in the PDC.

3. Create IAPs in the PDC available for purchase in the app. The example assumes
the following SKU IDs exist:

- `consumable`: A managed product.
- `upgrade`: A managed product.
- `subscription_silver`: A lower level subscription.
- `subscription_gold`: A higher level subscription.

Make sure that all of the products are set to `ACTIVE`.

4. Update `APP_ID` in `example/android/app/build.gradle` to match your package
ID in the PDC.

5. Create an `example/android/keystore.properties` file with all your signing
information. `keystore.example.properties` exists as an example to follow.
It's impossible to use any of the `BillingClient` APIs from an unsigned APK.
See
[here](https://developer.android.com/studio/publish/app-signing#secure-shared-keystore)
and [here](https://developer.android.com/studio/publish/app-signing#sign-apk)
for more information.

6. Build a signed apk. `flutter build apk` will work for this, the gradle files
in this project have been configured to sign even debug builds.

7. Upload the signed APK from step 6 to the PDC, and publish that to the alpha
test channel. Add your test account as an approved tester. The
`BillingClient` APIs won't work unless the app has been fully published to
the alpha channel and is being used by an authorized test account. See
[here](https://support.google.com/googleplay/android-developer/answer/3131213)
for more info.

8. Sign in to the test device with the test account from step #7. Then use
`flutter run` to install the app to the device and test like normal.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

// Load the build signing secrets from a local `keystore.properties` file.
// TODO(YOU): Create release keys and a `keystore.properties` file. See
// `example/README.md` for more info and `keystore.example.properties` for an
// example.
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
def configured = true
try {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
} catch (IOException e) {
configured = false
logger.error('Release signing information not found.')
}

project.ext {
// TODO(YOU): Create release keys and a `keystore.properties` file. See
// `example/README.md` for more info and `keystore.example.properties` for an
// example.
APP_ID = configured ? keystoreProperties['appId'] : "io.flutter.plugins.inapppurchaseexample.DEFAULT_DO_NOT_USE"
KEYSTORE_STORE_FILE = configured ? rootProject.file(keystoreProperties['storeFile']) : null
KEYSTORE_STORE_PASSWORD = keystoreProperties['storePassword']
KEYSTORE_KEY_ALIAS = keystoreProperties['keyAlias']
KEYSTORE_KEY_PASSWORD = keystoreProperties['keyPassword']
VERSION_CODE = configured ? keystoreProperties['versionCode'].toInteger() : 1
VERSION_NAME = configured ? keystoreProperties['versionName'] : "0.0.1"
}

if (project.APP_ID == "io.flutter.plugins.inapppurchaseexample.DEFAULT_DO_NOT_USE") {
configured = false
logger.error('Unique package name not set, defaulting to "io.flutter.plugins.inapppurchaseexample.DEFAULT_DO_NOT_USE".')
}

// Log a final error message if we're unable to create a release key signed
// build for an app configured in the Play Developer Console. Apks built in this
// condition won't be able to call any of the BillingClient APIs.
if (!configured) {
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.')
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
signingConfigs {
release {
storeFile project.KEYSTORE_STORE_FILE
storePassword project.KEYSTORE_STORE_PASSWORD
keyAlias project.KEYSTORE_KEY_ALIAS
keyPassword project.KEYSTORE_KEY_PASSWORD
}
}

compileSdkVersion 29

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
applicationId project.APP_ID
minSdkVersion 16
targetSdkVersion 29
versionCode project.VERSION_CODE
versionName project.VERSION_NAME
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
// Google Play Billing APIs only work with apps signed for production.
debug {
if (configured) {
signingConfig signingConfigs.release
} else {
signingConfig signingConfigs.debug
}
}
release {
if (configured) {
signingConfig signingConfigs.release
} else {
signingConfig signingConfigs.debug
}
}
}

testOptions {
unitTests.returnDefaultValues = true
}
}

flutter {
source '../..'
}

dependencies {
implementation 'com.android.billingclient:billing:3.0.2'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.json:json:20180813'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.inapppurchaseexample">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="in_app_purchase_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".EmbeddingV1Activity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
</activity>
<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data android:name="flutterEmbedding" android:value="2"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.inapppurchaseexample;

import android.os.Bundle;
import dev.flutter.plugins.integration_test.IntegrationTestPlugin;
import io.flutter.plugins.inapppurchase.InAppPurchasePlugin;
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin;

@SuppressWarnings("deprecation")
public class EmbeddingV1Activity extends io.flutter.app.FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IntegrationTestPlugin.registerWith(
registrarFor("dev.flutter.plugins.integration_test.IntegrationTestPlugin"));
SharedPreferencesPlugin.registerWith(
registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
InAppPurchasePlugin.registerWith(
registrarFor("io.flutter.plugins.inapppurchase.InAppPurchasePlugin"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.inapppurchaseexample;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.integration_test.FlutterTestRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterTestRunner.class)
@SuppressWarnings("deprecation")
public class EmbeddingV1ActivityTest {
@Rule
public ActivityTestRule<EmbeddingV1Activity> rule =
new ActivityTestRule<>(EmbeddingV1Activity.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.inapppurchaseexample;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.integration_test.FlutterTestRunner;
import io.flutter.embedding.android.FlutterActivity;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterTestRunner.class)
public class FlutterActivityTest {
@Rule
public ActivityTestRule<FlutterActivity> rule = new ActivityTestRule<>(FlutterActivity.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
}

allprojects {
repositories {
google()
jcenter()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
storePassword=???
keyPassword=???
keyAlias=???
storeFile=???
appId=io.flutter.plugins.inapppurchaseexample.DEFAULT_DO_NOT_USE
versionCode=1
versionName=0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
Loading