Cannot build APK for Android all of a sudden

Error building Player: CommandInvokationFailure: Failed to build apk. See the Console for details.
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java -Xmx2048M -Dcom.android.sdkmanager.toolsdir=“/Users/frj/dev/tools/android-sdk-macosx/tools” -Dfile.encoding=UTF8 -jar “/Applications/Unity/Unity.app/Contents/BuildTargetTools/AndroidPlayer/sdktools.jar” -

stderr[
Error: Duplicate file(s) in apk: ‘/Users/frj/dev/App-Unity/src/App-Unity/Temp/StagingArea/raw.ap_’
]
stdout[

]

I deleted the entire src/App-Unity folder and checked everything out from Git again - Unity wrote this in the console ‘Rebuilding Library because the asset database could not be found!’ - after that I was able to build apk files again.

Is there a nicer way of triggering the asset database rebuild than deleting everything?

I had the same error message when building for Android. My issue was related to having the same file in my Assets
\StreamingAssets and Assets\Plugins\Android\assets folders.

Right mouse click in the project window → re-import all

I would have thought that too - and did try it. But it did not help for some unknown reason.

Indeed that was the case - It sure would be helpfull if the console error named the duplicate entries. In large projects it can be quite a pain to find such problems.

1 Like

There’s a better way to do that with git, simply go to the root folder of your git project in the console, and type…

git clean -f -x -d

This will clean the entire folder of files that are not in the repository.
Though before you do it…

1.) Make sure Unity is closed.
2.) Make sure your working directory is clean