Skip to content

Commit 19c5560

Browse files
grabbouthymikeeAnimaSA
committed
feat: run-android respects applicationId from build.gradle when running app (#934)
* Get and use LaunchPackageName in place of pacakageNameWithSuffix Build system may alter application id for build and flavor purposes. This commit alters the system to not need a packageNameWithSuffix, but instead pull the launch package name directly from the merged manifest and use that to launch it on the device. * cleanup getLaunchPackageName into it's own file * Cleanup style * Added flowtyping to getLaunchPackageName, added a jest test for it. Also fixed some faulty RegExps as a result of testing. * Fix grammar in comment * Move sample files for test to __fixtures__ * Update paths to be OS-agnostic * Tests passing, barring Windows pathing issue with snapshot * build flavor test * move code to platform-android * reuse test helpers * fix typescript * Convert tests to typescript - part 1 * Update index.ts Co-authored-by: Michał Pierzchała <thymikee@gmail.com> Co-authored-by: Chris Fanti <animabolt@gmail.com>
1 parent 9d1df97 commit 19c5560

File tree

11 files changed

+679
-34
lines changed

11 files changed

+679
-34
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
apply plugin: "com.android.application"
2+
3+
import com.android.build.OutputFile
4+
5+
/**
6+
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7+
* and bundleReleaseJsAndAssets).
8+
* These basically call `react-native bundle` with the correct arguments during the Android build
9+
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10+
* bundle directly from the development server. Below you can see all the possible configurations
11+
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12+
* `apply from: "../../node_modules/react-native/react.gradle"` line.
13+
*
14+
* project.ext.react = [
15+
* // the name of the generated asset file containing your JS bundle
16+
* bundleAssetName: "index.android.bundle",
17+
*
18+
* // the entry file for bundle generation
19+
* entryFile: "index.android.js",
20+
*
21+
* // whether to bundle JS and assets in debug mode
22+
* bundleInDebug: false,
23+
*
24+
* // whether to bundle JS and assets in release mode
25+
* bundleInRelease: true,
26+
*
27+
* // whether to bundle JS and assets in another build variant (if configured).
28+
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29+
* // The configuration property can be in the following formats
30+
* // 'bundleIn${productFlavor}${buildType}'
31+
* // 'bundleIn${buildType}'
32+
* // bundleInFreeDebug: true,
33+
* // bundleInPaidRelease: true,
34+
* // bundleInBeta: true,
35+
*
36+
* // whether to disable dev mode in custom build variants (by default only disabled in release)
37+
* // for example: to disable dev mode in the staging build type (if configured)
38+
* devDisabledInStaging: true,
39+
* // The configuration property can be in the following formats
40+
* // 'devDisabledIn${productFlavor}${buildType}'
41+
* // 'devDisabledIn${buildType}'
42+
*
43+
* // the root of your project, i.e. where "package.json" lives
44+
* root: "../../",
45+
*
46+
* // where to put the JS bundle asset in debug mode
47+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48+
*
49+
* // where to put the JS bundle asset in release mode
50+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51+
*
52+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
53+
* // require('./image.png')), in debug mode
54+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55+
*
56+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
57+
* // require('./image.png')), in release mode
58+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59+
*
60+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
63+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64+
* // for example, you might want to remove it from here.
65+
* inputExcludes: ["android/**", "ios/**"],
66+
*
67+
* // override which node gets called and with what additional arguments
68+
* nodeExecutableAndArgs: ["node"],
69+
*
70+
* // supply additional arguments to the packager
71+
* extraPackagerArgs: []
72+
* ]
73+
*/
74+
75+
project.ext.react = [
76+
entryFile: "index.js"
77+
]
78+
79+
apply from: "../../node_modules/react-native/react.gradle"
80+
81+
android {
82+
compileSdkVersion rootProject.ext.compileSdkVersion
83+
84+
compileOptions {
85+
sourceCompatibility JavaVersion.VERSION_1_8
86+
targetCompatibility JavaVersion.VERSION_1_8
87+
}
88+
89+
defaultConfig {
90+
applicationId "com.mycompany.app"
91+
minSdkVersion rootProject.ext.minSdkVersion
92+
targetSdkVersion rootProject.ext.targetSdkVersion
93+
94+
versionCode 1
95+
versionName "1.0.0"
96+
}
97+
splits {
98+
abi {
99+
reset()
100+
enable enableSeparateBuildPerCPUArchitecture
101+
universalApk false
102+
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
103+
}
104+
}
105+
buildTypes {
106+
debug {
107+
applicationIdSuffix ".debug"
108+
versionNameSuffix "-build-" + getDate()
109+
}
110+
111+
releaseStaging {
112+
applicationIdSuffix ".staging"
113+
versionNameSuffix "-staging"
114+
matchingFallbacks = ['release']
115+
}
116+
117+
release {
118+
minifyEnabled enableProguardInReleaseBuilds
119+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
120+
}
121+
}
122+
123+
applicationVariants.all { variant ->
124+
variant.outputs.each { output ->
125+
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
126+
def abi = output.getFilter(OutputFile.ABI)
127+
if (abi != null) {
128+
output.versionCodeOverride =
129+
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
130+
}
131+
}
132+
}
133+
}
134+
135+
dependencies {
136+
implementation project(':react-native-config')
137+
implementation project(':react-native-webview')
138+
implementation project(':react-native-sound')
139+
implementation project(':react-native-gesture-handler')
140+
implementation fileTree(dir: "libs", include: ["*.jar"])
141+
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
142+
implementation "com.facebook.react:react-native:+" // From node_modules
143+
}
144+
145+
// Run this once to be able to run the application with BUCK
146+
// puts all compile dependencies into folder libs for BUCK to use
147+
task copyDownloadableDepsToLibs(type: Copy) {
148+
from configurations.compile
149+
into 'libs'
150+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
apply plugin: "com.android.application"
2+
3+
import com.android.build.OutputFile
4+
5+
/**
6+
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7+
* and bundleReleaseJsAndAssets).
8+
* These basically call `react-native bundle` with the correct arguments during the Android build
9+
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10+
* bundle directly from the development server. Below you can see all the possible configurations
11+
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12+
* `apply from: "../../node_modules/react-native/react.gradle"` line.
13+
*
14+
* project.ext.react = [
15+
* // the name of the generated asset file containing your JS bundle
16+
* bundleAssetName: "index.android.bundle",
17+
*
18+
* // the entry file for bundle generation
19+
* entryFile: "index.android.js",
20+
*
21+
* // whether to bundle JS and assets in debug mode
22+
* bundleInDebug: false,
23+
*
24+
* // whether to bundle JS and assets in release mode
25+
* bundleInRelease: true,
26+
*
27+
* // whether to bundle JS and assets in another build variant (if configured).
28+
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29+
* // The configuration property can be in the following formats
30+
* // 'bundleIn${productFlavor}${buildType}'
31+
* // 'bundleIn${buildType}'
32+
* // bundleInFreeDebug: true,
33+
* // bundleInPaidRelease: true,
34+
* // bundleInBeta: true,
35+
*
36+
* // whether to disable dev mode in custom build variants (by default only disabled in release)
37+
* // for example: to disable dev mode in the staging build type (if configured)
38+
* devDisabledInStaging: true,
39+
* // The configuration property can be in the following formats
40+
* // 'devDisabledIn${productFlavor}${buildType}'
41+
* // 'devDisabledIn${buildType}'
42+
*
43+
* // the root of your project, i.e. where "package.json" lives
44+
* root: "../../",
45+
*
46+
* // where to put the JS bundle asset in debug mode
47+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48+
*
49+
* // where to put the JS bundle asset in release mode
50+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51+
*
52+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
53+
* // require('./image.png')), in debug mode
54+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55+
*
56+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
57+
* // require('./image.png')), in release mode
58+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59+
*
60+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
63+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64+
* // for example, you might want to remove it from here.
65+
* inputExcludes: ["android/**", "ios/**"],
66+
*
67+
* // override which node gets called and with what additional arguments
68+
* nodeExecutableAndArgs: ["node"],
69+
*
70+
* // supply additional arguments to the packager
71+
* extraPackagerArgs: []
72+
* ]
73+
*/
74+
75+
project.ext.react = [
76+
entryFile: "index.js"
77+
]
78+
79+
apply from: "../../node_modules/react-native/react.gradle"
80+
81+
android {
82+
compileSdkVersion rootProject.ext.compileSdkVersion
83+
84+
compileOptions {
85+
sourceCompatibility JavaVersion.VERSION_1_8
86+
targetCompatibility JavaVersion.VERSION_1_8
87+
}
88+
89+
defaultConfig {
90+
applicationId "com.mycompany.app"
91+
minSdkVersion rootProject.ext.minSdkVersion
92+
targetSdkVersion rootProject.ext.targetSdkVersion
93+
94+
versionCode 1
95+
versionName "1.0.0"
96+
}
97+
splits {
98+
abi {
99+
reset()
100+
enable enableSeparateBuildPerCPUArchitecture
101+
universalApk false
102+
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
103+
}
104+
}
105+
buildTypes {
106+
debug {
107+
applicationIdSuffix ".debug"
108+
versionNameSuffix "-build-" + getDate()
109+
}
110+
111+
releaseStaging {
112+
applicationIdSuffix ".staging"
113+
versionNameSuffix "-staging"
114+
matchingFallbacks = ['release']
115+
}
116+
117+
release {
118+
minifyEnabled enableProguardInReleaseBuilds
119+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
120+
}
121+
}
122+
// Specifies one flavor dimension.
123+
flavorDimensions "version"
124+
productFlavors {
125+
demo {
126+
// Assigns this product flavor to the "version" flavor dimension.
127+
// This property is optional if you are using only one dimension.
128+
dimension "version"
129+
applicationIdSuffix ".demo"
130+
versionNameSuffix "-demo"
131+
}
132+
full {
133+
dimension "version"
134+
applicationIdSuffix ".full"
135+
versionNameSuffix "-full"
136+
}
137+
}
138+
139+
applicationVariants.all { variant ->
140+
variant.outputs.each { output ->
141+
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
142+
def abi = output.getFilter(OutputFile.ABI)
143+
if (abi != null) {
144+
output.versionCodeOverride =
145+
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
146+
}
147+
}
148+
}
149+
}
150+
151+
dependencies {
152+
implementation project(':react-native-config')
153+
implementation project(':react-native-webview')
154+
implementation project(':react-native-sound')
155+
implementation project(':react-native-gesture-handler')
156+
implementation fileTree(dir: "libs", include: ["*.jar"])
157+
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
158+
implementation "com.facebook.react:react-native:+" // From node_modules
159+
}
160+
161+
// Run this once to be able to run the application with BUCK
162+
// puts all compile dependencies into folder libs for BUCK to use
163+
task copyDownloadableDepsToLibs(type: Copy) {
164+
from configurations.compile
165+
into 'libs'
166+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.mycompany.app.debug"
4+
android:versionCode="1"
5+
android:versionName="1.0.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="16"
9+
android:targetSdkVersion="28" />
10+
11+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
12+
<uses-permission android:name="android.permission.INTERNET" /> <!-- Required by older versions of Google Play services to create GCM registration tokens -->
13+
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
14+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
15+
16+
<application
17+
android:name="com.mycompany.app.MainApplication"
18+
android:allowBackup="false"
19+
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
20+
android:debuggable="true"
21+
android:icon="@mipmap/ic_launcher"
22+
android:label="@string/APPLICATION_NAME"
23+
android:networkSecurityConfig="@xml/react_native_config"
24+
android:roundIcon="@mipmap/ic_launcher_round"
25+
android:theme="@style/AppTheme" >
26+
<activity
27+
android:name="com.mycompany.app.MainActivity"
28+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
29+
android:label="@string/APPLICATION_NAME"
30+
android:screenOrientation="userLandscape"
31+
android:windowSoftInputMode="adjustResize" >
32+
<intent-filter>
33+
<action android:name="android.intent.action.MAIN" />
34+
35+
<category android:name="android.intent.category.LAUNCHER" />
36+
</intent-filter>
37+
</activity>
38+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
39+
40+
<provider
41+
android:name="com.reactnativecommunity.webview.RNCWebViewFileProvider"
42+
android:authorities="com.greentubepro.android.star.debug.fileprovider"
43+
android:exported="false"
44+
android:grantUriPermissions="true" >
45+
<meta-data
46+
android:name="android.support.FILE_PROVIDER_PATHS"
47+
android:resource="@xml/file_provider_paths" />
48+
</provider>
49+
50+
<receiver
51+
android:name="com.learnium.RNDeviceInfo.RNDeviceReceiver"
52+
android:enabled="true"
53+
android:exported="true" >
54+
<intent-filter>
55+
<action android:name="com.android.vending.INSTALL_REFERRER" />
56+
</intent-filter>
57+
</receiver>
58+
59+
<activity
60+
android:name="com.google.android.gms.common.api.GoogleApiActivity"
61+
android:exported="false"
62+
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
63+
64+
<meta-data
65+
android:name="com.google.android.gms.version"
66+
android:value="@integer/google_play_services_version" />
67+
</application>
68+
69+
</manifest>

0 commit comments

Comments
 (0)