Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able to release apk in release mode - build failed #363

Closed
sharkguto opened this issue Jun 1, 2016 · 26 comments
Closed

not able to release apk in release mode - build failed #363

sharkguto opened this issue Jun 1, 2016 · 26 comments

Comments

@sharkguto
Copy link

sharkguto commented Jun 1, 2016

I am trying to release my apk without success using android_new option.
Whenever i try to build in release mode it crash... on debug mode i have success.

Someone can help me? I dont know what is this env.P4A_RELEASE_KEYSTORE variable... I tried to set in .spec, without sucess

image

output

gustavo@gustavo-VirtualBox:/jaspion$ buildozer --version
Check configuration tokens
Buildozer 0.33dev
gustavo@gustavo-VirtualBox:
/jaspion$

`INFO: lotoguess2 has compatible recipes, using this one
INFO: -> directory context /home/gustavo/jaspion/.buildozer/android/platform/build/dists/lotoguess2
INFO: -> running ant release
working: BUILD FAILED INFO: STDOUT (last 20 lines of 111):
[aapt](skipping file)

-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating LotoGuess-1.0.2-release-unsigned.apk for release...

-post-package:

-release-prompt-for-password:

-release-nosign:

-release-sign:
[echo] Signing final apk...

BUILD FAILED
/home/gustavo/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml:1135: The following error occurred while executing this line:
/home/gustavo/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml:1147: /home/gustavo/jaspion/.buildozer/android/platform/build/dists/lotoguess2/${env.P4A_RELEASE_KEYSTORE} (No such file or directory)

Total time: 14 seconds

cd /home/gustavo/jaspion/.buildozer/android/platform/build/dists/lotoguess2 && /home/gustavo/.buildozer/android/platform/apache-ant-1.9.4/bin/ant release

[WARNING]: ERROR: /home/gustavo/.buildozer/android/platform/apache-ant-1.9.4/bin/ant failed!

Command failed: python -m pythonforandroid.toolchain --color=always --storage-dir=/home/gustavo/jaspion/.buildozer/android/platform/build apk --bootstrap=sdl2 --dist_name lotoguess2 --name 'Loto Guess' --version 1.0.2 --package com.gmftech.lotoguess2 --android_api 19 --minsdk 14 --private /home/gustavo/jaspion/.buildozer/android/app --permission CAMERA --permission INTERNET --permission ACCESS_NETWORK_STATE --permission WRITE_EXTERNAL_STORAGE --add-jar /home/gustavo/jaspion/lib-jars/AdBuddiz-KivyPlugin-3.1.11.jar --presplash /home/gustavo/jaspion/./data/lotto_icon.png --icon /home/gustavo/jaspion/./data/icon_verde.png --orientation portrait --release --copy-libs

Buildozer failed to execute the last command

The error might be hidden in the log above this error

Please read the full log, and search for it before

raising an issue with buildozer itself.

In case of a bug report, please add a full log with log_level = 2

`

Spec:

[app]

sudo pip install https://github.com/kivy/buildozer/archive/master.zip

(str) Title of your application

title = Loto Guess

(str) Package name

package.name = lotoguess2

(str) Package domain (needed for android/ios packaging)

package.domain = com.gmftech

(str) Source code where the main.py live

source.dir = .

(list) Source files to include (let empty to include all the files)

source.include_exts = py,png,jpg,kv,atlas,ttf,mo

(list) List of inclusions using pattern matching

source.include_patterns = assets/,images/.png

(list) Source files to exclude (let empty to not exclude anything)

source.exclude_exts = spec

(list) List of directory to exclude (let empty to not exclude anything)

source.exclude_dirs = tests, bin

(list) List of exclusions using pattern matching

source.exclude_patterns = license,images//.jpg

(str) Application versioning (method 1)

version = 1.0.2

(str) Application versioning (method 2)

version.regex = version = '"['"]

version.filename = %(source.dir)s/main.py

(list) Application requirements

comma seperated e.g. requirements = sqlite3,kivy

requirements = kivy,jinja2,openssl,requests,simplejson

kivy==master

(str) Custom source folders for requirements

Sets custom source for any requirements with recipes

requirements.source.kivy = ../../kivy

(list) Garden requirements

garden_requirements = recycleview

(str) Presplash of the application

presplash.filename = %(source.dir)s/data/lotto_icon.png

presplash.filename = %(source.dir)s/data/Lucky_Coin.png

presplash.filename = %(source.dir)s/data/loading.png

(str) Icon of the application

icon.filename = %(source.dir)s/data/icon_verde.png

(str) Supported orientation (one of landscape, portrait or all)

orientation = portrait

(list) List of service to declare

services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY

OSX Specific

author = © Copyright Info

Android specific

(bool) Indicate if the application should be fullscreen or not

fullscreen = 1

(list) Permissions

android.permissions = CAMERA,INTERNET,ACCESS_NETWORK_STATE,WRITE_EXTERNAL_STORAGE

,ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION

(int) Android API to use

android.api = 19

(int) Minimum API required

android.minapi = 14

(int) Android SDK version to use

android.sdk = 23

(str) Android NDK version to use

android.ndk = 10e

(bool) Use --private data storage (True) or --dir public storage (False)

android.private_storage = True

(str) Android NDK directory (if empty, it will be automatically downloaded.)

android.ndk_path = /home/gustavo/crystax-ndk-10.3.1

(str) Android SDK directory (if empty, it will be automatically downloaded.)

android.sdk_path =

(str) ANT directory (if empty, it will be automatically downloaded.)

android.ant_path =

(str) python-for-android git clone directory (if empty, it will be automatically cloned from github)

android.p4a_dir = /home/gustavo/python-for-android

(list) python-for-android whitelist

android.p4a_whitelist =

(bool) If True, then skip trying to update the Android sdk

This can be useful to avoid excess Internet downloads or save time

when an update is due and you just want to test/build your package

android.skip_update = False

(str) Bootstrap to use for android builds (android_new only)

android.bootstrap = sdl2

(str) Android entry point, default is ok for Kivy-based app

android.entrypoint = org.renpy.android.PythonActivity

(list) List of Java .jar files to add to the libs so that pyjnius can access

their classes. Don't add jars that you do not need, since extra jars can slow

down the build process. Allows wildcards matching, for example:

OUYA-ODK/libs/*.jar

android.add_jars = foo.jar,bar.jar,path/to/more/*.jar

android.add_jars = lib-jars/*.jar

P4A_RELEASE_KEYSTORE = keystores/lotoguess-release-key.keystore

(list) List of Java files to add to the android project (can be java or a

directory containing the files)

android.add_src =

(str) python-for-android branch to use, if not master, useful to try

not yet merged features.

android.branch = master

(str) OUYA Console category. Should be one of GAME or APP

If you leave this blank, OUYA support will not be enabled

android.ouya.category = GAME

(str) Filename of OUYA Console icon. It must be a 732x412 png image.

android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png

(str) XML file to include as an intent filters in tag

android.manifest.intent_filters =

(list) Android additionnal libraries to copy into libs/armeabi

android.add_libs_armeabi = libs/android/*.so

android.add_libs_armeabi_v7a = libs/android-v7/*.so

android.add_libs_x86 = libs/android-x86/*.so

android.add_libs_mips = libs/android-mips/*.so

(bool) Indicate whether the screen should stay on

Don't forget to add the WAKE_LOCK permission if you set this to True

android.wakelock = False

(list) Android application meta-data to set (key=value format)

android.meta_data =

(list) Android library project to add (will be added in the

project.properties automatically.)

android.library_references =

android.meta_data = com.google.android.gms.version=@integer/google_play_services_version

android.library_references = google-play-services_lib

(str) Android logcat filters to use

android.logcat_filters = *:S python:D

(bool) Copy library instead of making a libpymodules.so

android.copy_libs = 1

iOS specific

(str) Path to a custom kivy-ios folder

ios.kivy_ios_dir = ../kivy-ios

(str) Name of the certificate to use for signing the debug version

Get a list of available identities: buildozer ios list_identities

ios.codesign.debug = "iPhone Developer: ()"

(str) Name of the certificate to use for signing the release version

ios.codesign.release = %(ios.codesign.debug)s

[buildozer]

(int) Log level (0 = error only, 1 = info, 2 = debug (with command output))

log_level = 2

(int) Display warning if buildozer is run as root (0 = False, 1 = True)

warn_on_root = 1

(str) Path to build artifact storage, absolute or relative to spec file

build_dir = ./.buildozer

(str) Path to build output (i.e. .apk, .ipa) storage

bin_dir = ./bin

-----------------------------------------------------------------------------

List as sections

You can define all the "list" as [section:key].

Each line will be considered as a option to the list.

Let's take [app] / source.exclude_patterns.

Instead of doing:

[app]

source.exclude_patterns = license,data/audio/.wav,data/images/original/

This can be translated into:

[app:source.exclude_patterns]

license

data/audio/*.wav

data/images/original/*

-----------------------------------------------------------------------------

Profiles

You can extend section / key with a profile

For example, you want to deploy a demo version of your application without

HD content. You could first change the title to add "(demo)" in the name

and extend the excluded directories to remove the HD content.

[app@demo]

title = My Application (demo)

[app:source.exclude_patterns@demo]

images/hd/*

Then, invoke the command line with the "demo" profile:

buildozer --profile demo android debug

@sharkguto
Copy link
Author

i have set variable on terminal, and now i am able to create the release apk, however it is unasign.... :(

so i did the asing manually, however the apk does not run.
On debug mode, apk run awesome, on release it crash.... any ideas?

export P4A_RELEASE_KEYSTORE=keystores/lotoguess-release-key.keystore
export P4A_RELEASE_KEYSTORE_PASSWD=xxxxxxxxxxxxxxxxx
export P4A_RELEASE_KEYALIAS_PASSWD=xxxxxxxxxxxxxxxxxx
export P4A_RELEASE_KEYALIAS=lotoguess

my manually script to asing

#!/bin/bash
#/home/gustavo/.buildozer/android/platform/android-sdk-23/platform-tools/adb kill-server

select FILENAME in $(ls /home/gustavo/jaspion/bin/*.apk | grep -i release)
do
break
done

echo "voce escolheu a apk -> "$FILENAME
echo "agora forneça o path da sua keystore:"
#read -e -p "keystore Path:" KEYSTORE

VERSION=$(echo $FILENAME | awk '{sub(/-release./,""); print}' | awk '{sub(/.-/,""); print}')
echo "versao: "$VERSION

KEYSTORE=/home/gustavo/jaspion/keystores/lotoguess-release-key.keystore

echo $KEYSTORE
echo
echo "validando jarsingner"
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $KEYSTORE $FILENAME lotoguess

echo "validando zipalign"
/home/gustavo/.buildozer/android/platform/android-sdk-23/build-tools/23.0.1/zipalign -v 4 $FILENAME /home/gustavo/jaspion/bin/LotoGuess-$VERSION.apk

echo
echo "arquivo pronto /home/gustavo/jaspion/bin/LotoGuess-$VERSION.apk"

rm $FILENAME

@ecdsa
Copy link

ecdsa commented Oct 13, 2016

I have the same issue.
buildozer requires the keystore password in order to sign the apk, and then it copies an unsigned apk in the bin directory
I have to sign it with jarsigner

@akshayaurora akshayaurora reopened this Oct 13, 2016
@manoonam
Copy link

manoonam commented Nov 3, 2016

@ecdsa, Were you able to resolve this issue? I'm hitting it as well.

@ecdsa
Copy link

ecdsa commented Nov 4, 2016

@bearnun it is not resolved, but I can still create an apk.
I pass the keystore password to buildozer, and it creates an unsigned apk.
then I sign the apk with jarsigner & zipalign

@fedecaccia
Copy link

@ecdsa How can i pass to buildozer the keystore password?

@brentpicasso
Copy link
Contributor

Running into this as well. Currently I'm relying on my own mechanism for signing my .apk.

is there a way to have buildozer build a release apk and not sign it?

@nirghum
Copy link

nirghum commented Jul 5, 2017

I've got same problem. Please anybody comment the solution. Thanks

@brentpicasso
Copy link
Contributor

brentpicasso commented Jul 5, 2017

What I've done since is change my build process to pass the signing information to buildozer by setting the appropriate environment variables:

export P4A_RELEASE_KEYSTORE=((path to your keystore))
export P4A_RELEASE_KEYSTORE_PASSWD=((keystore password))
export P4A_RELEASE_KEYALIAS_PASSWD=((key alias password))
export P4A_RELEASE_KEYALIAS=((key alias))

Switching to this approach ended up working for me.

@AndreMiras
Copy link
Member

FWIW this is documented here:
https://github.com/kivy/kivy/wiki/Creating-a-Release-APK

@nirghum
Copy link

nirghum commented Jul 7, 2017

@brentpicass but how to change build process? How to edit the setting? Thanks.

@AndreMiras
Copy link
Member

@brentpicass, this is what worked for me:
https://github.com/AndreMiras/PyWallet/blob/develop/docs/Release.md#commands
So creating the certificate and setting the env.

@nirghum
Copy link

nirghum commented Jul 7, 2017

@AndreMiras is there any videos about this? or can you explain it more precisely?

@AndreMiras
Copy link
Member

Well I'm not too sure what to add.
Set the variables and use the keytool to create your signing certificate. Then when you use buildozer it will read the variables and know how to use your signed certificate. Also read https://developer.android.com/studio/publish/app-signing.html and related topics to understand the idea behind it.

@kowsar89
Copy link

@AndreMiras @inclement
I'm not sure why an important topic like this isn't resolved yet!
And it's true, there's no step by step tutorial about this by kivy team, like they don't care!

In kivy documentation it's mentioned like this:

my-project - The directory for your project
my-new-key - The name of the key you generate
my-alias - A short alias name for the key
MyProject - The name of your project, and APK
version - The version of this APK (not Kivy version)

My question is,

  1. How do I generate a key?
  2. What is this "my-alias" used for and what possible values could I use for "my-alias"?
  3. Do I have to run all the commands from virtualenv if my kivy app is installed inside vietualenv?

@brentpicasso
Copy link
Contributor

Generating the artifacts for signing an APK is an Android level process, separate from Kivy. The assumption is you already have the signing certificate + key, or you know how to do it already.

There is some good information out there already - here's one place in the Android developer documentation:
https://developer.android.com/studio/publish/app-signing.html

@kowsar89
Copy link

@brentpicasso Your assumption is wrong and I don't know how to do it already, and as I'm using kivy I expected a detailed official documentation/tutorial from their website but didn't find any, so honestly I'm losing interest in it. Yes I understand it's a separate process but that doesn't mean a detailed docs will cause any harm.

@AndreMiras
Copy link
Member

@kowsar89 I think that instruction page was just a draft. It's indeed no very furnished or up to date, but at least it's there. It was a good start for me to know where to look. And it's also our duty to contribute and improve it. I've just updated with the link to the official documentation @brentpicasso shared.

Regarding your questions, see my answers below and as you ramp up feel free to update the wiki :)
Disclaimer: I'm totally not an expert.

  1. How do I generate a key?

This is what I did:
keytool -genkey -v -keystore ~/.android/<my-new-key>.keystore -alias <my-alias> -keyalg RSA -keysize 2048 -validity 10000

  1. What is this "my-alias" used for and what possible values could I use for "my-alias"?

As I understood it's just as string to identify your keystore. I use "release" or "debug" as alias names.

  1. Do I have to run all the commands from virtualenv if my kivy app is installed inside vietualenv?

I'm not sure what you mean here. But in my setup my app dependencies are installed in the virtualenv, but it doesn't matter because buildozer is not part of the venv. So no, I run keytool and buildozer outside the virtualenv.

Regarding the wiki doc, I personally ended up forking my own and updating only my project documentation, because I didn't dare to update their wiki for things I wasn't sure of. But it indeed feels like some things are outdated lile:

  1. They switch to the venv and run python2 -m buildozer android_new release. But I use buildozer directly.
  2. Same thing with jarsigner and zipalign, I totally skip it and I'm assuming it's handled by buildozer.

Don't feel discouraged, it indeed requires time to get into it, but keep in mind Kivy is not a commercial product. And it's not something I would really recommend for production anyway. I personally see it more as a toy (no offence guys :p). So play with it and have fun!

@kowsar89
Copy link

@AndreMiras
Thanks for detailed answer. Can I use any value for <my-new-key> or I have to generate it in some way?

@inclement
Copy link
Member

inclement commented Sep 12, 2017

As far as I'm concerned, https://developer.android.com/studio/publish/app-signing.html#signing-manually is the official documentation - there is basically no difference here between how to do it for a Kivy app or a Java app. In particular, you can follow the steps in 'Build an unsigned APK and sign it manually', except you can skip step 1 because you already have the APK.

A more detailed explanation of this would be welcome in the python-for-android docs. I hadn't noticed there isn't much, although that's partly because I haven't seen it mentioned for a while.

This issue thread appears to originally describe a more specific problem with how python-for-android behaves. I thought this was fixed, and that the current behaviour would be to build a release APK without signing (which is the intended result). Is this what happens with buildozer android release at the moment?

@AndreMiras
Copy link
Member

@inclement

I thought this was fixed, and that the current behaviour would be to build a release APK without signing (which is the intended result). Is this what happens with buildozer android release at the moment?

No, I think running buildozer android release also signs the APK using the 4 exported env variables as input. So basically when I publish a new version to the store, I just export theses variables and run buildozer. It will build it and sign the APK.

@kowsar89

Thanks for detailed answer. Can I use any value for or I have to generate it in some way?

From the keytool manual:

Similarly, if the -keystore ks_file option is specified but ks_file does not exist, then it is created.

So yes this is how I've generated my key.

@inclement
Copy link
Member

inclement commented Sep 12, 2017

No, I think running buildozer android release also signs the APK using the 4 exported env variables as input. So basically when I publish a new version to the store, I just export theses variables and run buildozer. It will build it and sign the APK.

Sorry, I meant that it should run (and produce an unsigned apk) by default if these variables are not provided. That was the reason for this original bug - it would crash instead of proceeding without signing if the variables weren't set.

@AndreMiras
Copy link
Member

Ah OK, so yes then it still crashes the application if the variables are not provided, see truncated output trace below.

buildozer android release
...
-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating PyWallet-2017.0909-release-unsigned.apk for release...

-post-package:

-release-prompt-for-password:

-release-nosign:

-release-sign:
     [echo] Signing final apk...

BUILD FAILED
/home/ubuntu/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml:1139: The following error occurred while executing this line:
/home/ubuntu/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml:1151: /home/ubuntu/workspace/PyWallet/.buildozer/android/platform/build/dists/pywallet/${env.P4A_RELEASE_KEYSTORE} (No such file or directory)

Total time: 4 seconds


  STDERR:


[INFO]:    STDOUT (last 20 lines of 107):
             [aapt]     (skipping file '.gitkeep' due to ANDROID_AAPT_IGNORE pattern '.*')

-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating PyWallet-2017.0909-release-unsigned.apk for release...

-post-package:

-release-prompt-for-password:

-release-nosign:

-release-sign:
     [echo] Signing final apk...

BUILD FAILED
/home/ubuntu/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml:1139: The following error occurred while executing this line:
/home/ubuntu/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml:1151: /home/ubuntu/workspace/PyWallet/.buildozer/android/platform/build/dists/pywallet/${env.P4A_RELEASE_KEYSTORE} (No such file or directory)

Total time: 4 seconds
[INFO]:    STDERR:

[INFO]:    COMMAND:
cd /home/ubuntu/workspace/PyWallet/.buildozer/android/platform/build/dists/pywallet && /home/ubuntu/.buildozer/android/platform/apache-ant-1.9.4/bin/ant release

[WARNING]: ERROR: /home/ubuntu/.buildozer/android/platform/apache-ant-1.9.4/bin/ant failed!
# Command failed: /usr/bin/python -m pythonforandroid.toolchain apk --debug --bootstrap=sdl2 --dist_name pywallet --name PyWallet --version 2017.0909 --package com.github.andremiras.pywallet --android_api 19 --sdk 19 --minsdk 9 --private /home/ubuntu/workspace/PyWallet/.buildozer/android/app --permission INTERNET --presplash /home/ubuntu/workspace/PyWallet/docs/images/icon.png --icon /home/ubuntu/workspace/PyWallet/docs/images/icon.png --orientation portrait --window --release --sign --copy-libs --local-recipes /home/ubuntu/workspace/PyWallet/src/python-for-android/recipes --whitelist /home/ubuntu/workspace/PyWallet/whitelist.txt --blacklist /home/ubuntu/workspace/PyWallet/blacklist.txt --arch armeabi-v7a --color=always --storage-dir=/home/ubuntu/workspace/PyWallet/.buildozer/android/platform/build
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

So in this case the error was:

/home/ubuntu/.buildozer/android/platform/android-sdk-20/tools/ant/build.xml:1151: /home/ubuntu/workspace/PyWallet/.buildozer/android/platform/build/dists/pywallet/${env.P4A_RELEASE_KEYSTORE} (No such file or directory)

If I set this variable and run it again, it will fail again with the other missing variables.

@inclement
Copy link
Member

Okay, thanks. It looks like I did fix this in p4a, and it will only assume that the variables exist if passed the --sign argument (with the sdl2 bootstrap). However, buildozer passes this automatically: https://github.com/kivy/buildozer/blob/master/buildozer/targets/android_new.py#L94

Probably this line should be removed, and added as an option somehow.

@AndreMiras
Copy link
Member

Also related to #851

@AndreMiras
Copy link
Member

Probably fixed in previous commit plus #835

@jbsidis
Copy link

jbsidis commented Sep 5, 2020

That key should be gotten automatically, the best recommendation is, Delete the the .buildozer directory completely, then cd to the directory where your project is, then buildozer -v android debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests