@@ -13,7 +13,6 @@ import { Builder, parseString } from "xml2js";
1313import {
1414 IRuntimeGradleVersions ,
1515 INodePackageManager ,
16- IAndroidToolsInfo ,
1716 IWatchIgnoreListService ,
1817} from "../declarations" ;
1918import { IPlatformsDataService } from "../definitions/platform" ;
@@ -47,7 +46,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
4746 private $fs : IFileSystem ,
4847 private $childProcess : IChildProcess ,
4948 private $hostInfo : IHostInfo ,
50- private $androidToolsInfo : IAndroidToolsInfo ,
5149 private $logger : ILogger ,
5250 private $packageManager : INodePackageManager ,
5351 private $projectData : IProjectData ,
@@ -423,6 +421,31 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
423421 ) ;
424422 this . replaceFileContent ( buildGradlePath , "{{pluginName}}" , pluginName ) ;
425423 this . replaceFileContent ( settingsGradlePath , "{{pluginName}}" , pluginName ) ;
424+
425+ // gets the package from the AndroidManifest to use as the namespace or fallback to the `org.nativescript.${shortPluginName}`
426+ const shortPluginName = getShortPluginName ( pluginName ) ;
427+
428+ const manifestPath = path . join (
429+ pluginTempDir ,
430+ "src" ,
431+ "main" ,
432+ "AndroidManifest.xml"
433+ ) ;
434+ const manifestContent = this . $fs . readText ( manifestPath ) ;
435+
436+ let packageName = `org.nativescript.${ shortPluginName } ` ;
437+ const xml = await this . getXml ( manifestContent ) ;
438+ if ( xml [ "manifest" ] ) {
439+ if ( xml [ "manifest" ] [ "$" ] [ "package" ] ) {
440+ packageName = xml [ "manifest" ] [ "$" ] [ "package" ] ;
441+ }
442+ }
443+
444+ this . replaceFileContent (
445+ buildGradlePath ,
446+ "{{pluginNamespace}}" ,
447+ packageName
448+ ) ;
426449 }
427450
428451 private async getRuntimeGradleVersions (
@@ -777,18 +800,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
777800 private async buildPlugin (
778801 pluginBuildSettings : IBuildAndroidPluginData
779802 ) : Promise < void > {
780- if ( ! pluginBuildSettings . androidToolsInfo ) {
781- this . $androidToolsInfo . validateInfo ( {
782- showWarningsAsErrors : true ,
783- validateTargetSdk : true ,
784- projectDir : pluginBuildSettings . projectDir ,
785- } ) ;
786- pluginBuildSettings . androidToolsInfo =
787- this . $androidToolsInfo . getToolsInfo ( {
788- projectDir : pluginBuildSettings . projectDir ,
789- } ) ;
790- }
791-
792803 const gradlew =
793804 pluginBuildSettings . gradlePath ??
794805 ( this . $hostInfo . isWindows ? "gradlew.bat" : "./gradlew" ) ;
@@ -798,8 +809,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
798809 pluginBuildSettings . pluginDir ,
799810 "assembleRelease" ,
800811 `-PtempBuild=true` ,
801- `-PcompileSdk=android-${ pluginBuildSettings . androidToolsInfo . compileSdkVersion } ` ,
802- `-PbuildToolsVersion=${ pluginBuildSettings . androidToolsInfo . buildToolsVersion } ` ,
803812 `-PappPath=${ this . $projectData . getAppDirectoryPath ( ) } ` ,
804813 `-PappResourcesPath=${ this . $projectData . getAppResourcesDirectoryPath ( ) } ` ,
805814 ] ;
0 commit comments