Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
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: 2 additions & 0 deletions 2 lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ interface INsConfigAndroid extends INsConfigPlaform {
enableLineBreakpoints?: boolean;

enableMultithreadedJavascript?: boolean;

gradleVersion?: string;
}

interface INsConfigHooks {
Expand Down
30 changes: 28 additions & 2 deletions 30 lib/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,18 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
this.$fs.copyFile(path.join(dir, "*"), destination);
}
}

private extractNamespaceFromManifest(manifestPath:string): string {
const fileContent = this.$fs.readText(manifestPath);
const contentRegex = new RegExp('package="(.*)"');
const match = fileContent.match(contentRegex);
let namespace: string;
if (match) {
namespace = match[1];
const replacedFileContent = fileContent.replace(contentRegex, "");
this.$fs.writeFile(manifestPath, replacedFileContent);
}
return namespace;
}
private async setupGradle(
pluginTempDir: string,
platformsAndroidDirPath: string,
Expand All @@ -413,14 +424,29 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
const runtimeGradleVersions = await this.getRuntimeGradleVersions(
projectDir
);
let gradleVersion = runtimeGradleVersions.gradleVersion;
if (this.$projectData.nsConfig.android.gradleVersion) {
gradleVersion = this.$projectData.nsConfig.android.gradleVersion;
}
this.replaceGradleVersion(
pluginTempDir,
runtimeGradleVersions.gradleVersion
gradleVersion
);
this.replaceGradleAndroidPluginVersion(
buildGradlePath,
runtimeGradleVersions.gradleAndroidPluginVersion
);

// In gradle 8 every android project must have a namespace in "android"
// and the package property in manifest is now forbidden
// let s replace it
const manifestFilePath = this.getManifest(path.join(pluginTempDir, 'src', 'main'));
let pluginNamespace = this.extractNamespaceFromManifest(manifestFilePath);
if (!pluginNamespace) {
pluginNamespace = pluginName.replace(/@/g, '').replace(/[/-]/g, '.')
}

this.replaceFileContent(buildGradlePath, "{{pluginNamespace}}", pluginNamespace);
this.replaceFileContent(buildGradlePath, "{{pluginName}}", pluginName);
this.replaceFileContent(settingsGradlePath, "{{pluginName}}", pluginName);
}
Expand Down
29 changes: 29 additions & 0 deletions 29 lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,24 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
gradleSettingsFilePath
);


const gradleVersion = projectData.nsConfig.android.gradleVersion;
if (gradleVersion) {
// user defined a custom gradle version, let's apply it
const gradleWrapperFilePath = path.join(
this.getPlatformData(projectData).projectRoot,
"gradle",
"wrapper",
"gradle-wrapper.properties"
);
shell.sed(
"-i",
/gradle-([0-9.]+)-bin.zip/,
`gradle-${gradleVersion}-bin.zip`,
gradleWrapperFilePath
);
}

try {
// will replace applicationId in app/App_Resources/Android/app.gradle if it has not been edited by the user
const appGradleContent = this.$fs.readText(projectData.appGradlePath);
Expand Down Expand Up @@ -487,6 +505,17 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
projectData.projectIdentifiers.android,
manifestPath
);
const buildGradlePath = path.join(
this.getPlatformData(projectData).projectRoot,
"app",
"build.gradle"
);
shell.sed(
"-i",
/__PACKAGE__/,
projectData.projectIdentifiers.android,
buildGradlePath
);
}

private getProjectNameFromId(projectData: IProjectData): string {
Expand Down
40 changes: 25 additions & 15 deletions 40 vendor/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ buildscript {
}
def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.8.20" }
def kotlinVersion = computeKotlinVersion()
def computeBuildToolsVersion = { ->
project.hasProperty("androiBuildToolsVersion") ? buildToolsVersion : "{{runtimeAndroidPluginVersion}}"
}
def androiBuildToolsVersion = computeBuildToolsVersion()
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:{{runtimeAndroidPluginVersion}}'
classpath "com.android.tools.build:gradle:$androiBuildToolsVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

// NOTE: Do not place your application dependencies here; they belong
Expand Down Expand Up @@ -152,6 +156,7 @@ def computeBuildToolsVersion = { ->
}

android {
namespace "{{pluginNamespace}}"
def applyPluginGradleConfigurations = { ->
nativescriptDependencies.each { dep ->
def includeGradlePath = "${getDepPlatformDir(dep)}/include.gradle"
Expand All @@ -166,6 +171,11 @@ android {
compileSdkVersion computeCompileSdkVersion()
buildToolsVersion computeBuildToolsVersion()

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

defaultConfig {
targetSdkVersion computeTargetSdkVersion()
versionCode 1
Expand Down Expand Up @@ -205,24 +215,24 @@ task addDependenciesFromNativeScriptPlugins {
}
}

afterEvaluate {
def generateBuildConfig = project.hasProperty("generateBuildConfig") ? project.generateBuildConfig : false
def generateR = project.hasProperty("generateR") ? project.generateR : false
generateReleaseBuildConfig.enabled = generateBuildConfig
generateDebugBuildConfig.enabled = generateBuildConfig
generateReleaseResValues.enabled = generateR
generateDebugResValues.enabled = generateR
}

tasks.whenTaskAdded({ DefaultTask currentTask ->
if (currentTask.name == 'bundleRelease' || currentTask.name == 'bundleDebug') {
// This wont work with gradle 8 + should be the same as the code just after
// afterEvaluate {
// def generateBuildConfig = project.hasProperty("generateBuildConfig") ? project.generateBuildConfig : false
// def generateR = project.hasProperty("generateR") ? project.generateR : false
// generateReleaseBuildConfig.enabled = generateBuildConfig
// generateDebugBuildConfig.enabled = generateBuildConfig
// generateReleaseResValues.enabled = generateR
// generateDebugResValues.enabled = generateR
// }
project.tasks.configureEach {
if (name == 'bundleRelease') {
def generateBuildConfig = project.hasProperty("generateBuildConfig") ? project.generateBuildConfig : false
def generateR = project.hasProperty("generateR") ? project.generateR : false
if (!generateBuildConfig) {
currentTask.exclude '**/BuildConfig.class'
it.exclude '**/BuildConfig.class'
}
if (!generateR) {
currentTask.exclude '**/R.class', '**/R$*.class'
it.exclude '**/R.class', '**/R$*.class'
}
}
})
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.