1
\$\begingroup\$

So I Created A manifest file in Assets/Plugin/Android/. The File contains:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
 <activity android:name="com.unity3d.player.UnityPlayerActivity" android:windowSoftInputMode="stateHidden"></activity>
</manifest> 

Error Occurs when building:

NullReferenceException: Object reference not set to an instance of an object

UnityEditor.AndroidManifest.SetApplicationFlag (System.String name, Boolean value)

UnityEditor.AndroidManifest.SetDebuggable (Boolean debuggable)

I followed the docs from here, about Overriding the Android Manifest.

The apk builds fine when the manifest is removed.

Complete Error:

NullReferenceException: Object reference not set to an instance of an object UnityEditor.AndroidManifest.SetApplicationFlag (System.String name, Boolean value) UnityEditor.AndroidManifest.SetDebuggable (Boolean debuggable) UnityEditor.Android.PostProcessor.Tasks.GenerateManifest.PatchManifest (UnityEditor.Android.PostProcessor.PostProcessorContext context, System.String manifest) UnityEditor.Android.PostProcessor.Tasks.GenerateManifest.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup targetGroup, BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:286) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

UNITY 2018.3.4f1

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

While the NullReferenceException is technically a bug that Unity should protect against and present something nicer to the user, your manifest is not complete. The main thing it’s complaining about is that it doesn’t have an <application> tag wrapping the activity. You should base your manifest on the one provided by Unity.

To see it, remove your copy, make a build, then check the version it created, which can be found in your project folder at Temp/StagingArea/AndroidManifest.xml. Just copy that file and make modifications to that.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks Ed, your answer saved my day. The problem is solved by just including activity tag inside application tag. And you don't have to provide whole manifest in plugin/Android just provide what you need in correct syntax. Unity overrides the main manifest with the modification. As you mentioned i checked the AndroidManidest.xml at Temp/StagingArea/ after build and it contains the modifiation. :) \$\endgroup\$
    – coder_86
    Feb 5, 2019 at 16:03
1
\$\begingroup\$

What's Happening Now

By providing your own Manifest file in Assets/Plugins/Android, you are declaring that your Manifest should be considered the main one, and Unity will try to inject any extras into that one.

As the main Manifest, your file would have to provide all the basic requirements and have the correct well-formed structure, according to the standard Android Manifest file documentation.

What you Want to Happen

That depends on (A) the needs of your project, and (B) how familiar you are with Android development. If you don't need any customization, then the default auto-generated Manifest created by Unity will be fine. Just delete your file as you have done, and build as normal.

However, if you do need additional Android-specific customization, then you can either:

  • provide a well-formed main Manifest (including all required tags/structure and your customizations) in Assets/Plugins/Android within your Unity project
  • OR build as normal, but edit the final Manifest file that Unity auto-generates to your requirements

Generally speaking, Android Manifest files are straightforward configuration files written in XML. If you read & follow the documentation, and understand what your project needs are, then you can write one by hand without much trouble.

That said, from an ongoing maintenance perspective, once you create your own Manifest, you "own" it, and will be required to keep up with any necessary changes as either your project needs change or Android itself evolves. Unless you are interested in Android development particularly, or are otherwise prepared to keep your Manifest up-to-date, your best bet may be to stick with the auto-generated file by Unity.


(For Advanced Users: As an Android dev, I feel compelled to mention that in modern professional Android development, the Manifest is only one part of the larger build system. If you actually need to get "under the hood" and tweak your Android build in a more than trivial manner, then Gradle build configuration is worth looking into.)

\$\endgroup\$
5
  • \$\begingroup\$ Isn't there a way to just provide the modification and unity will apply the modification to the manifest and keep the rest as default. The plugins also contains manifest files but they aren't well formed. Here's the manifest from play service plugin....<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="schemas.android.com/apk/res/android" package="com.google.games.bridge" android:versionCode="1" > <application/> </manifest> \$\endgroup\$
    – coder_86
    Feb 5, 2019 at 15:26
  • \$\begingroup\$ That manifest from the Play Services plugin is well-formed - it has a self-closing "application" tag, and a "manifest" tag with a full package name and version code. Your OP manifest was missing all of that. \$\endgroup\$
    – MandisaW
    Feb 5, 2019 at 16:16
  • \$\begingroup\$ @helpMePlz - I'm still not sure what modifications you wanted to make in the first place though. Unity already sets the PlayerActivity class and the keyboard/softInputMode by default. \$\endgroup\$
    – MandisaW
    Feb 5, 2019 at 16:17
  • 1
    \$\begingroup\$ As I mentioned in Ed marty's comment section It worked by just including <activity> tag inside <application> tag without a need to provide the whole manifest file and than applying the modification to it. This way I don't have to worry about maintaining it with new version no and etc every time I build my app. And about the modification I was just reading the documentation about overriding manifest file and wanted to try it out. Thank you for taking your time to answer my question. \$\endgroup\$
    – coder_86
    Feb 5, 2019 at 16:29
  • 1
    \$\begingroup\$ No problem. You may still want to consider maintaining an app version number independent of Unity's build cycle. If you plan on publishing to app stores, it's useful/required. Good luck! \$\endgroup\$
    – MandisaW
    Feb 5, 2019 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .