Skip to content

Commit

Permalink
Merge pull request #1813 from flexn-io/fix/android_app/build.gradle_o…
Browse files Browse the repository at this point in the history
…verrides

bring back the injection {{PLUGIN_APPLY}} to app/build.gradle
  • Loading branch information
pauliusguzas authored Dec 3, 2024
2 parents d0e14db + e41a0de commit 8d0c0a6
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 58 deletions.
1 change: 0 additions & 1 deletion packages/core/jsonSchema/renative-1.0.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@
}
}
},
"required": ["repositories", "dependencies", "ext", "custom"],
"additionalProperties": false
},
"injectAfterAll": {
Expand Down
6 changes: 0 additions & 6 deletions packages/core/jsonSchema/rnv.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,6 @@
}
}
},
"required": [
"repositories",
"dependencies",
"ext",
"custom"
],
"additionalProperties": false
},
"injectAfterAll": {
Expand Down
1 change: 0 additions & 1 deletion packages/core/jsonSchema/rnv.plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@
}
}
},
"required": ["repositories", "dependencies", "ext", "custom"],
"additionalProperties": false
},
"injectAfterAll": {
Expand Down
6 changes: 0 additions & 6 deletions packages/core/jsonSchema/rnv.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,6 @@
}
}
},
"required": [
"repositories",
"dependencies",
"ext",
"custom"
],
"additionalProperties": false
},
"injectAfterAll": {
Expand Down
6 changes: 0 additions & 6 deletions packages/core/jsonSchema/rnv.templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,6 @@
}
}
},
"required": [
"repositories",
"dependencies",
"ext",
"custom"
],
"additionalProperties": false
},
"injectAfterAll": {
Expand Down
14 changes: 8 additions & 6 deletions packages/core/src/schema/platforms/fragments/templateAndroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ const templateAndroid = z
build_gradle: z
.object({
plugins: z.array(z.string()),
buildscript: z.object({
repositories: z.array(z.string()),
dependencies: z.array(z.string()),
ext: z.array(z.string()),
custom: z.array(z.string()),
}),
buildscript: z
.object({
repositories: z.array(z.string()),
dependencies: z.array(z.string()),
ext: z.array(z.string()),
custom: z.array(z.string()),
})
.partial(),
injectAfterAll: z.array(z.string()),
})
.partial()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
{{PLUGIN_APPLY}}

{{PLUGIN_LOCAL_PROPERTIES}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
{{PLUGIN_APPLY}}

{{PLUGIN_LOCAL_PROPERTIES}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

{{PLUGIN_APPLY}}

{{PLUGIN_LOCAL_PROPERTIES}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
{{PLUGIN_APPLY}}

{{PLUGIN_LOCAL_PROPERTIES}}

Expand Down
71 changes: 40 additions & 31 deletions packages/sdk-android/src/gradleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import {
import path from 'path';
import { getBuildFilePath, getAppId, getAppVersion, getAppVersionCode, addSystemInjects } from '@rnv/sdk-utils';
import { Context, getContext } from './getContext';
import { TemplateAndroid } from './types';

const currentOs = process.platform === 'darwin' ? 'osx' : process.platform === 'win32' ? 'win64' : 'linux64';

export const parseBuildGradleSync = () => {
const c = getContext();
const appFolder = getAppFolder();


const templateAndroid = getConfigProp('templateAndroid');
const buildscript = templateAndroid?.build_gradle?.buildscript;

Expand Down Expand Up @@ -325,6 +325,9 @@ ${chalk().bold.white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`
${releaseBuildTypes.join('\n ')}
}`;

// APP/BUILD.GRADLE
_parseAppBuildGradleObject(appBuildGradle);

// MULTI APK
// const versionCodeOffset = getConfigProp('versionCodeOffset', 0);
const isMultiApk = getConfigProp('multipleAPKs') === true;
Expand Down Expand Up @@ -666,36 +669,7 @@ export const parseAndroidConfigObject = (plugin?: ConfigPluginPlatformSchema, ke
const templateAndroid = plugin?.templateAndroid;

const appBuildGradle = templateAndroid?.app_build_gradle;
if (appBuildGradle) {
if (appBuildGradle.apply) {
appBuildGradle.apply.forEach((v) => {
c.payload.pluginConfigAndroid.applyPlugin += `apply ${sanitizePluginPath(v, key)}\n`;
});
}

if (appBuildGradle.defaultConfig) {
appBuildGradle.defaultConfig.forEach((v) => {
c.payload.pluginConfigAndroid.defaultConfig += `${sanitizePluginPath(v, key)}\n`;
});
}

const { implementations } = appBuildGradle;
if (implementations) {
implementations.forEach((v) => {
c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` implementation ${sanitizePluginPath(
v,
key
)}\n`;
});
}

const afterEvaluate = appBuildGradle?.afterEvaluate;
if (afterEvaluate) {
afterEvaluate.forEach((v) => {
c.payload.pluginConfigAndroid.appBuildGradleAfterEvaluate += ` ${sanitizePluginPath(v, key)}\n`;
});
}
}
_parseAppBuildGradleObject(appBuildGradle, key);

// BUILD.GRADLE
const buildGradle = templateAndroid?.build_gradle;
Expand Down Expand Up @@ -740,6 +714,41 @@ const _fixAndroidLegacy = (c: RnvContext, modulePath: string) => {
}
};

const _parseAppBuildGradleObject = (appBuildGradle: TemplateAndroid['app_build_gradle'] | undefined, key = '') => {
const c = getContext();
if (appBuildGradle) {
if (appBuildGradle.apply) {
appBuildGradle.apply.forEach((v) => {
c.payload.pluginConfigAndroid.applyPlugin += v.includes('apply')
? `${sanitizePluginPath(v, key)}\n`
: `apply ${sanitizePluginPath(v, key)}\n`;
});
}

if (appBuildGradle.defaultConfig) {
appBuildGradle.defaultConfig.forEach((v) => {
c.payload.pluginConfigAndroid.defaultConfig += `${sanitizePluginPath(v, key)}\n`;
});
}

const { implementations } = appBuildGradle;
if (implementations) {
implementations.forEach((v) => {
c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` implementation ${sanitizePluginPath(
v,
key
)}\n`;
});
}

const afterEvaluate = appBuildGradle?.afterEvaluate;
if (afterEvaluate) {
afterEvaluate.forEach((v) => {
c.payload.pluginConfigAndroid.appBuildGradleAfterEvaluate += ` ${sanitizePluginPath(v, key)}\n`;
});
}
}
};
// const _getPrivateConfig = (c, platform) => {
// let privateConfigFolder = path.join(c.paths.workspace.dir, c.files.project.package.name, c.buildConfig.id);
// if (!fsExistsSync(privateConfigFolder)) {
Expand Down

0 comments on commit 8d0c0a6

Please sign in to comment.