Apk not signed with keystore file when building in Gradle

I’m trying to sign my apk with the keystore file I created following the Unity instructions. But after I successfully build the apk, using jarsigner to verify it always showed signed by “Android Debug” instead of the actual Company Name.

I’m using Gradle to build the apk and with Devlopment Build option on, which builds fine but not signed properly. If I turn off the Development Build option, it shows the error of
“FileNotFoundException: Temp\gradleOut\build\outputs\apk\gradleOut-release.apk does not exist”

Can anyone let me know how I can test with the signing of apk? Thanks and I’m using Unity 5.6.3p1.

Hi!

The “Android Debug” signing is the expected behavior for a development build. As for the “FileNotFoundException” - is this the whole error? If not, could you please post the full error?

1 Like

I’m experiencing the same behaviour when trying to build, using Unity 5.6.2f1. Here’s the full error I get

FileNotFoundException: Temp\gradleOut\build\outputs\apk\gradleOut-release.apk does not exist
System.IO.File.Move (System.String sourceFileName, System.String destFileName) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:318)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.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.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup targetGroup, BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:186)
UnityEditor.HostView:OnGUI()

There’s no other errors in my console and I don’t see anything else in the editor log that might be helpful.

Sounds like gradle build failed. There should be something about it in the console and Editor.log.

I get this in the editor log just before the error, sounds like the manifest failed to merge I guess, I’ll take a look into this and report back if I find a solution.

[Temp\StagingArea\AndroidManifest-main.xml:1, C:\Users\UserName\Documents\Unity\ProjectName\Temp\StagingArea\android-libraries\AN_Res\AndroidManifest.xml:2] /manifest/supports-screens defined in library, missing from main manifest:
(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

FileNotFoundException: Temp\gradleOut\build\outputs\apk\gradleOut-release.apk does not exist

Yeah perhaps an incomplete main manifest, the one in Assets/Plugins/Android/AndroidManifest.xml

So I managed to successfully build. The problem was unrelated to the manifest issue, I had set up the signing of my mainTemplate.gradle file incorrectly.

https://stackoverflow.com/questions/22156199/gradle-produces-unsigned-release-apk
After making the changes suggested in here I was able to build successfully.

“Basically, you add a “signinConfig”, in where you specify the location an password of the keystore. Then, in the release build type, refer to that signing configuration.”

...
android {
   ...
   defaultConfig { ... }
   signingConfigs {
       release {
           storeFile file("myreleasekey.keystore")
           storePassword "password"
           keyAlias "MyReleaseKey"
           keyPassword "password"
       }
   }
   buildTypes {
       release {
           ...
           signingConfig signingConfigs.release
       }
   }
}
...

As a side note I keep my keystore in my project directory and so had to move up 2 directories from ProjectDirectory/Temp/gradleOut in order to find my keystore like so:
storeFile file(“…/…/KEYSTORE_NAME.keystore”).

Right now my game immediately crashes on device on launch with “Unfortunately, [App Name] has stopped” but that’s very likely a totally seperate issue I have to look into.

2 Likes

Thanks for that response vasco_jd, that did it for me!

That solved it @jd_vasco . Thank you :slight_smile:

I manually changed my old unity Gradle to a higher version (gradle-5.6.2) and as a result I also was getting “FileNotFoundException: Temp\gradleOut\build\outputs\apk\gradleOut-release.apk does not exist” error on my Unity 5.6.6f2, but my APK in fact was created in “apk*release*\gradleOut-release.apk” folder, so I added this line to my mainTemplate.gradle and it worked:

android {
    ...
    applicationVariants.all { variant ->
        delete "build/outputs/apk/";

        variant.outputs.all {
            outputFileName = "../gradleOut-" + variant.buildType.name + ".apk"
        }
    }
}
1 Like