Bug 210 - Cannot build projects with package names that start with numbers
Summary: Cannot build projects with package names that start with numbers
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Tools and Addins ()
Version: 1.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Andreia Gaita
URL:
: 2624 ()
Depends on:
Blocks:
 
Reported: 2011-08-05 19:31 UTC by Joseph Hill
Modified: 2012-04-25 11:27 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Joseph Hill 2011-08-05 19:31:54 UTC
Building a Mono for Android project with a . in the path will fail.

1) Create a new Mono for Android Solution. Name it: mfa1.0.2_2
2) Build and Run

Expected results:
Running app

Actual results:
Creating package

Build started 8/5/2011 7:14:56 PM.
__________________________________________________
Project "/Users/jhill/tmp/Projects/mfa1.0.2_2/mfa1.0.2_2.csproj" (SignAndroidPackage target(s)):

	Target _GenerateAndroidAssetsDir:
	No output files were specified for target _GenerateAndroidAssetsDir, skipping.

	Target _GenerateAndroidResourceDir:
	Skipping target "_GenerateAndroidResourceDir" because its outputs are up-to-date.

	Target _ResolveMonoAndroidSdks:
		MonoAndroid Tools: /Developer/MonoAndroid/usr/lib/mandroid/
		MonoAndroid Framework: /Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8;/Developer/MonoAndroid/usr/lib/mono/2.1
		Android SDK: /Users/jhill/Downloads/android-sdk-mac_86/
		Java SDK: /usr/

	Target _ValidateAndroidPackageProperties:
		GetAndroidPackageName Task
		  ManifestFile: 
		  AssemblyName: mfa1.0.2_2
		  PackageName: mfa1.0.2_2

	Target _UpdateAndroidResgen:
	Skipping target "_UpdateAndroidResgen" because its outputs are up-to-date.

	Target PrepareForBuild:
		Configuration: Debug Platform: AnyCPU

	Target GenerateSatelliteAssemblies:
	No input files were specified for target GenerateSatelliteAssemblies, skipping.

	Target CoreCompile:
	Skipping target "CoreCompile" because its outputs are up-to-date.

	Target _ResolveAndroidSigningKey:
		Tool /usr/bin/keytool execution started with arguments: -genkeypair -alias "androiddebugkey" -dname "CN=Android Debug,O=Android,C=US" -storepass "android" -keypass "android" -keystore "obj/Debug/debug.keystore" 

	Target _CompileAndroidPackage:
		Mandroid Task
		  Assemblies: /Users/jhill/tmp/Projects/mfa1.0.2_2/bin/Debug/mfa1.0.2_2.dll; /Developer/MonoAndroid/usr/lib/mono/2.1/System.dll; /Developer/MonoAndroid/usr/lib/mono/2.1/System.Xml.dll; /Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8/Mono.Android.dll; /Developer/MonoAndroid/usr/lib/mono/2.1/System.Core.dll
		  I18nAssemblies: 
		  BuildDirectory: /Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/
		  ReferenceAssembliesDirectory: /Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8;/Developer/MonoAndroid/usr/lib/mono/2.1;/Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8;/Developer/MonoAndroid/usr/lib/mono/2.1
		  AndroidSdkDirectory: /Users/jhill/Downloads/android-sdk-mac_86/
		  JavaSdkDirectory: /usr/
		  AssetDirectory: /Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/assets/
		  AndroidSdkPlatform: 8
		  MonoAndroidToolsDirectory: /Developer/MonoAndroid/usr/lib/mandroid/
		  ResourceDirectory: /Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/res/
		  ManifestTemplate: 
		  Package: mfa1.0.2_2
		  NativeLibrary: 
		  JavaSource: 
		  Debug: True
		  UseSharedRuntime: True
		  SupportedAbis: armeabi
		  LinkMode: None
		  ExtraArgs:  
		Tool /Developer/MonoAndroid/usr/bin/mandroid execution started with arguments: -v --nosign --sdk-dir="/Users/jhill/Downloads/android-sdk-mac_86/" --builddir="/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/android" --framework-dir="/Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8" --framework-dir="/Developer/MonoAndroid/usr/lib/mono/2.1" --framework-dir="/Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8" --framework-dir="/Developer/MonoAndroid/usr/lib/mono/2.1" -S="/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/res/" --package="mfa1.0.2_2"   --nolink --abi="armeabi" --java-sdk-dir="/usr/" --debug --sdk-platform="8" "/Users/jhill/tmp/Projects/mfa1.0.2_2/bin/Debug/mfa1.0.2_2.dll" "/Developer/MonoAndroid/usr/lib/mono/2.1/System.dll" "/Developer/MonoAndroid/usr/lib/mono/2.1/System.Xml.dll" "/Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8/Mono.Android.dll" "/Developer/MonoAndroid/usr/lib/mono/2.1/System.Core.dll" 
		Running command: /Users/jhill/Downloads/android-sdk-mac_86/platform-tools/aapt "package" "-f" "-M" "AndroidManifest.xml" "-J" "src" "--custom-package" "mfa1.0.2_2" "-F" "bin/packaged_resources" "-S" "/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/res/" "-I" "/Users/jhill/Downloads/android-sdk-mac_86/platforms/android-8/android.jar"
			Process executed in: 00:00:00.5488180
		Running command: /usr/bin/javac "-d" "bin/classes" "-classpath" "/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/android/bin/mono.android.jar" "-bootclasspath" "/Users/jhill/Downloads/android-sdk-mac_86/platforms/android-8/android.jar" "-encoding" "UTF-8" "@/var/folders/Kw/KwI1RzwxFpeC7YXqv67VBk+++TI/-Tmp-/tmp17db651c.tmp"
		MonoDroid.Utils.CommandFailedException: Operation is not valid due to the current state of the object
		  at MonoDroid.Utils.ProcessRocks+<ReadStandardOutput>c__Iterator6.MoveNext () [0x00000] in <filename unknown>:0 
		  at Monodroid.Toolbox.InvokeCommand (IEnumerable`1 commandLine) [0x00000] in <filename unknown>:0 
		  at Monodroid.Toolbox.InvokeJavac (System.String src_path) [0x00000] in <filename unknown>:0 
		  at Monodroid.Droidinator.CreateDalvikBytecode (System.Collections.Generic.List`1 javaTypes, System.Collections.Generic.List`1 assemblies) [0x00000] in <filename unknown>:0 
		  at Monodroid.Droidinator.CreateApk () [0x00000] in <filename unknown>:0 
		  at Monodroid.MainClass.Main (System.String[] argv) [0x00000] in <filename unknown>:0 
		/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/android/src/R.java:8: ';' expected
		package mfa1.0.2_2;
		            ^
		1 error

/Library/Frameworks/Mono.framework/External/xbuild/Novell/Novell.MonoDroid.Common.targets: error : Tool exited with code: 1. Output: Running command: /Users/jhill/Downloads/android-sdk-mac_86/platform-tools/aapt "package" "-f" "-M" "AndroidManifest.xml" "-J" "src" "--custom-package" "mfa1.0.2_2" "-F" "bin/packaged_resources" "-S" "/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/res/" "-I" "/Users/jhill/Downloads/android-sdk-mac_86/platforms/android-8/android.jar"
	Process executed in: 00:00:00.5488180
Running command: /usr/bin/javac "-d" "bin/classes" "-classpath" "/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/android/bin/mono.android.jar" "-bootclasspath" "/Users/jhill/Downloads/android-sdk-mac_86/platforms/android-8/android.jar" "-encoding" "UTF-8" "@/var/folders/Kw/KwI1RzwxFpeC7YXqv67VBk+++TI/-Tmp-/tmp17db651c.tmp"
MonoDroid.Utils.CommandFailedException: Operation is not valid due to the current state of the object
  at MonoDroid.Utils.ProcessRocks+<ReadStandardOutput>c__Iterator6.MoveNext () [0x00000] in <filename unknown>:0 
  at Monodroid.Toolbox.InvokeCommand (IEnumerable`1 commandLine) [0x00000] in <filename unknown>:0 
  at Monodroid.Toolbox.InvokeJavac (System.String src_path) [0x00000] in <filename unknown>:0 
  at Monodroid.Droidinator.CreateDalvikBytecode (System.Collections.Generic.List`1 javaTypes, System.Collections.Generic.List`1 assemblies) [0x00000] in <filename unknown>:0 
  at Monodroid.Droidinator.CreateApk () [0x00000] in <filename unknown>:0 
  at Monodroid.MainClass.Main (System.String[] argv) [0x00000] in <filename unknown>:0 
/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/android/src/R.java:8: ';' expected
package mfa1.0.2_2;
            ^
1 error


	Task "Mandroid" execution -- FAILED
	Done building target "_CompileAndroidPackage" in project "/Users/jhill/tmp/Projects/mfa1.0.2_2/mfa1.0.2_2.csproj".-- FAILED

Done building project "/Users/jhill/tmp/Projects/mfa1.0.2_2/mfa1.0.2_2.csproj".-- FAILED

Build FAILED.
Errors:

/Users/jhill/tmp/Projects/mfa1.0.2_2/mfa1.0.2_2.csproj (SignAndroidPackage) ->
/Library/Frameworks/Mono.framework/External/xbuild/Novell/Novell.MonoDroid.Common.targets (_CompileAndroidPackage target) ->

	/Library/Frameworks/Mono.framework/External/xbuild/Novell/Novell.MonoDroid.Common.targets: error : Tool exited with code: 1. Output: Running command: /Users/jhill/Downloads/android-sdk-mac_86/platform-tools/aapt "package" "-f" "-M" "AndroidManifest.xml" "-J" "src" "--custom-package" "mfa1.0.2_2" "-F" "bin/packaged_resources" "-S" "/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/res/" "-I" "/Users/jhill/Downloads/android-sdk-mac_86/platforms/android-8/android.jar"
	Process executed in: 00:00:00.5488180
Running command: /usr/bin/javac "-d" "bin/classes" "-classpath" "/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/android/bin/mono.android.jar" "-bootclasspath" "/Users/jhill/Downloads/android-sdk-mac_86/platforms/android-8/android.jar" "-encoding" "UTF-8" "@/var/folders/Kw/KwI1RzwxFpeC7YXqv67VBk+++TI/-Tmp-/tmp17db651c.tmp"
MonoDroid.Utils.CommandFailedException: Operation is not valid due to the current state of the object
  at MonoDroid.Utils.ProcessRocks+<ReadStandardOutput>c__Iterator6.MoveNext () [0x00000] in <filename unknown>:0 
  at Monodroid.Toolbox.InvokeCommand (IEnumerable`1 commandLine) [0x00000] in <filename unknown>:0 
  at Monodroid.Toolbox.InvokeJavac (System.String src_path) [0x00000] in <filename unknown>:0 
  at Monodroid.Droidinator.CreateDalvikBytecode (System.Collections.Generic.List`1 javaTypes, System.Collections.Generic.List`1 assemblies) [0x00000] in <filename unknown>:0 
  at Monodroid.Droidinator.CreateApk () [0x00000] in <filename unknown>:0 
  at Monodroid.MainClass.Main (System.String[] argv) [0x00000] in <filename unknown>:0 
/Users/jhill/tmp/Projects/mfa1.0.2_2/obj/Debug/android/src/R.java:8: ';' expected
package mfa1.0.2_2;
            ^
1 error



	 0 Warning(s)
	 1 Error(s)

Time Elapsed 00:00:06.7188240

Package creation failed
Comment 1 Jonathan Pryor 2011-08-22 17:11:30 UTC
The problem isn't the '.', the problem is the number.

By default, if the assembly name contains a '.' (as "mfa1.0.2_2" does), then Mono for Android uses the assembly name as the package name, which is also used as the Java package name. There is thus an implicit requirement that the (dotted) assembly name be a valid package name, and package name parts can't start with an integer.

Oops.

We'll need to introduce some form of "encoding" so that numeric values are prefixed with e.g. '_', so that valid Java package names are created.
Comment 2 Jonathan Pryor 2012-04-20 09:13:29 UTC
This also hits hyphens:

http://stackoverflow.com/questions/8610982/monodroid-default-new-untouched-template-project-cannot-run-in-android-emulato

Instead of "fixing" these, we should flat out reject package names that don't conform to Android's requirements for package names:

    [A-Za-z]([A-Za-z0-9_]*)(.[A-Za-z]([A-Za-z0-9_]*)*

That is, a package name is made up of '.'-separated 'parts', and each part must start with an ASCII letter followed by ASCII letters, numbers, or underscore.

via PackageParser.validateName():

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/content/pm/PackageParser.java#L677
Comment 3 Jonathan Pobst 2012-04-20 10:24:50 UTC
The "fixing" comes into play because most projects don't specify a package name.  We simply take the AssemblyName, and if the AssemblyName doesn't have a period in it, we use AssemblyName.AssemblyName.

I agree with the regex for setting the package name in the GUI, but we also need to somehow fix our "automatic" package name generation.
Comment 4 Jonathan Pryor 2012-04-20 10:30:18 UTC
So what are the semantics of "fixing"? Replace all non-alphanumeric characters with '_' and prefix leading numbers with 'n'?

(Note: validateName() does not permit '_' to be the first character in a package name part, it must start with [A-Za-z].)

I'm leaning toward flat-out erroring on invalid package names, lest we get  bug reports of "I chose a package name of 'Foo.1' but my actual app has a package name of 'Foo.n1'!"
Comment 5 Jonathan Pobst 2012-04-20 10:39:21 UTC
They would not be able to choose a package name of 'Foo.1'.  We would add validation to setting the package name in the GUI.

The disconnect would be if they named their new project '7Cats'.  New projects by default do not have an AndroidManifest, so no package name is specified.  Our MSBuild tasks would then use N7Cats.N7Cats.  (Currently we would use 7Cats.7Cats)

I definitely see the disconnect, but it's not as bad as they chose an invalid package name.  And it's better than the current behavior of erroring out on a setting they never set.
Comment 6 Jonathan Pryor 2012-04-23 10:58:40 UTC
*** Bug 2624 has been marked as a duplicate of this bug. ***
Comment 7 Jonathan Pryor 2012-04-25 11:27:11 UTC
Fixed in 8aadb365.

We replace all invalid characters ([^A-Za-z0-9_]) with underscore ('_').

If a package name part starts with [0-9_], then we prefix it with 'x'. "Foo.1" thus becomes "Foo.x1", and "7Cats" would become "x7Cats.x7Cats".