kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.12k stars 1.82k forks source link

Google requiring API Target 26 in Aug/Nov 2018 #1219

Closed gorgonaut04 closed 5 years ago

gorgonaut04 commented 6 years ago

Just wanted to put it on the devs’ radar. We’ve been limited to 19 for the last couple years, afaik, but kivy will need to support targeting 26 for new apps starting in August, and for app updates starting in November: https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html?m=1

If there’s currently a straightforward way to target 21 or higher then I’ll stand corrected and be very interested in hearing how.

rnixx commented 5 years ago

@inclement you're right. if i go to settings -> apps and choose my app, storage permission is denied by default. when i grant permission manually, it works. will try to find a way to ask user for permission via jnius

inclement commented 5 years ago

See https://developer.android.com/training/permissions/requesting

rnixx commented 5 years ago

you were faster ;) just found it. this code might go to PythonActivity, and then be invoked from jnius or android, what do you think?

Malakanorth commented 5 years ago

Regarding the permission denied on /storage for me it was due to user_data_dir from kivy.app.

I have just tested the solution of @clevermindgames

from jnius import autoclass, cast
PythonActivity = autoclass('org.kivy.android.PythonActivity')
Environment = autoclass('android.os.Environment')
context = cast('android.content.Context', PythonActivity.mActivity)
private_storage = context.getExternalFilesDir(Environment.getDataDirectory().getAbsolutePath()).getAbsolutePath()

And it work fine, thanks @clevermindgames! private_storage return path /storage/emulated/0/Android/data/com.myapp/files/data

I can write to a file in this path without problem.

Malakanorth commented 5 years ago

Regarding the tools version I used for my build buildozer latest version installed from pip p4a latest version downloaded from github (zip file) android-ndk r16b downloaded manually android-sdk, I used my old version android-sdk-20 full updated with android tool (sdk tools,build-tools, platform-tools) openjdk-8

I have modified android-sdk-linux/tools/ant/build.xml

<property name="java.target" value="7" />
<property name="java.source" value="1.7" />

buildozer.spec

android.api = 19
android.minapi = 19
android.sdk = 23
android.ndk = 16b

I also modified some p4a files related to sdl2; check to this commit https://github.com/kivy/python-for-android/commit/f017eb9254c4dc179524e8d6e26f58600a39695a. Thanks @inclement for that.

But I had modified these files due to "__aeabi_memclr8" error. But this error appear when you build your app directly with API27. So I think this modification is not necessary because building in first with API19.

I hav build with API19, removed my dist directory and re-build with API27.

Many thanks to all. KIVY DEV team and community are great!!

Sorry for my english, I hope you understand me.

Malakanorth commented 5 years ago

@Zen-CODE. You must remove your dist after build with api19 because some files are «tagged» api19. This first build is just for compile libraries because it work with this api version. I hope it will work for you.

Le 24 sept. 2018 8:25 PM, "Richard Larkin" notifications@github.com a écrit :

@StacyMAI https://github.com/StacyMAI. Thanks a lot for the sharing that, but I am confused. I've used the same NDK and API, and the same "build for 19 then 27" approach but got reports that the APK was still refused by google. The only difference is that you clear the "dists" folder before rebuilding. I can confirm it solves the ftello error and runs on my phone, but I will reserve my explosions of gratitude and wonder when the store accepts the APK.

Unfortunately, it will take me a little while to test that. Our current app only builds with the old toolchain, so I need to solve those issues before I can build a new APK and upload. I will post back when I can confirm that it is accepted. Until then, I would encourage others to post their findings when using this process and uploading.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/kivy/python-for-android/issues/1219#issuecomment-424076003, or mute the thread https://github.com/notifications/unsubscribe-auth/AfrTeHbZPP-zja_GOJxtfnaKi1csoXFQks5ueSOjgaJpZM4RZ5U5 .

tkuam commented 5 years ago

So I've had success in building (with buildozer) and uploading my app to the play store using @StacyMAI 's method, however I'm having trouble getting the app to work with AdMob/KivMob. Currently when I attempt to run the app and it tries to use kivmob I get this error:

jnius.jnius.JavaException: Class not found 'org/kivy/android/PythonActivity$AdCmd'

The app works as expected when I comment out all the kivmob code.

Previously I built the app with python3crystax, python-for-android-admob/sdl2-admob and the ads worked as expected then, but then the API requirement went into effect and I haven't been successful building an apk with the crystax ndk so I've reverted to python2.7 and used @StacyMAI 's method which solved the API requirement problem but brought upon the issue with Admob.

I'm guessing it has something to do with not initially setting in my buildozer.spec the p4a source_dir to python-for-android-admob and p4a bootstrap to sdl2-admob, but I'm really not sure and am at a loss for where to go from here. I've tried setting the p4a source/bootstrap to the admob ones after an initial successful build, but the error still persists when I run the app, and when I set p4a source/bootstrap to the admob initially (before a successful build) I get a different error and the build is unsuccessful:

Include/Python.h:33:19: fatal error: stdio.h: No such file or directory
 #include <stdio.h>

Any thoughts on what I could try from here to get Admob working?

clevermindgames commented 5 years ago

Any thoughts on what I could try from here to get Admob working?

I have got Admob to work on API 27, here is the link: https://play.google.com/store/apps/details?id=au.com.quadropoly.quadropoly

I am not using custom bootstrap, instead I forked p4a and modified pythonforandroid\bootstraps\sdl2\build\src\main\java\org\kivy\android\PythonActivity.java inserting all the bits from sdl2-admob's PythonActivity.java file (the bits to insert are very well marked by / KivMob backend starts here. / and / End of KivMob code. /, great work MichaelStott! ) There is no need to insert google-play-services.jar as libs required could be added via buildozer: android.gradle_dependencies = 'com.google.android.gms:play-services-ads:15.0.0','com.android.support:appcompat-v7:26.1.0'

Hope it helps. At this point only banners and interstitial are working, but I am trying to add support for Rewarded Videos too.

tkuam commented 5 years ago

@clevermindgames I've added the sdl2-admob's PythonActivity.java KivMob code to the regular p4a's PythonActivity.java and when trying to build it looks like it's nearly successfully completing but I get an error:

> Could not resolve all dependencies for configuration ':_debugApkCopy'.
   > Could not find com.google.android.gms:play-services-ads:15.0.0.

and the same for com.android.support:appcompat-v7:26.1.0. I put those into my buildozer.spec for the gradle_dependecies but it doesn't seem to loading them properly. I'm pretty new to all of this so I could be missing something simple. Could I add the google-play-service.jar manually and if so where should it go? I'll keep poking around and hopefully I'm stumble on a solution, but thanks for the help and getting me started in the right direction!

OptimusGREEN commented 5 years ago

Regarding the permission denied on /storage for me it was due to user_data_dir from kivy.app.

I have just tested the solution of @clevermindgames

from jnius import autoclass, cast
PythonActivity = autoclass('org.kivy.android.PythonActivity')
Environment = autoclass('android.os.Environment')
context = cast('android.content.Context', PythonActivity.mActivity)
private_storage = context.getExternalFilesDir(Environment.getDataDirectory().getAbsolutePath()).getAbsolutePath()

And it work fine, thanks @clevermindgames! private_storage return path /storage/emulated/0/Android/data/com.myapp/files/data

I can write to a file in this path without problem.

This does work so thanks for that, however it is extremely slow at reading and writing data compared to writing to sdcard, assuming due to the jnius.

Getting permissions is still key here I think.

OptimusGREEN commented 5 years ago

As far as admob goes, maybe having a discussion on the kivy users group would be extremely beneficial to a lot of people?

clevermindgames commented 5 years ago

@tkuam No, don't add .jar manually: you can only get very old version of this library as a .jar and I doubt it will work properly with API 27. Try modifying this file, so the top 22 rows look like this pythonforandroid\bootstraps\sdl2\build\templates\build.tmpl.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
       jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
    }
}

allprojects {
    repositories {
        jcenter()
    mavenCentral()
    maven {
            url "https://maven.google.com"
        }
        flatDir {
            dirs 'libs'
        }
    }
}

Don't forget to buildozer android clean before rebuilding when modifying anything in p4a: it copies files from there only when it is clean.

clevermindgames commented 5 years ago

@OptimusGREEN getting this folder through jnius is slow, but you only need to do it once. Just store the results in some StringProperty and use it everywhere. Google labeled those permissions dangerous for a reason, and unless it is really required for the app it should be avoided. I used it to be able to share saved data between paid and free version of my App, now learning to live without it. There is also a benefit in using private storage for the app: when user backs up his phone's data, his SDcard content is not saved in a backup.

Zen-CODE commented 5 years ago

Okay, I can confirm the build APK per StaceyMAI's procedure runs without the ftello error AND is accepted by google. Yay. Thanks all.

@inclement. You mentioned a config file that incorrectly stores the previous config. Which one? If you give me some pointers, I can try to prepare a PR to fix that?

inclement commented 5 years ago

project.properties is the file.

tkuam commented 5 years ago

@clevermindgames I modified build.tmpl.gradle as you suggested and that seems to solve the need to find play-services-ads as my log shows it's been downloaded during the build, but now I've got a bunch of these errors for what seems like all of the various android widgets:

/home/tkuam/Desktop/wcpy2/.buildozer/android/platform/build/dists/workoutapp/build/intermediates/res/merged/debug/values-v26/values-v26.xml:14: error: Error: No resource found that matches the given name: attr 'android:touchscreenBlocksFocus'.

Not sure if it's related to the kivmob/admob changes or not, but I don't get these errors and successfully build when I don't make those changes.

Edit: Been poking around a bit, when I go to the directory and open up the .xml file(s) indicated in the error messages I'm getting, I'm finding the line that the error is referring to: <item name="android:touchscreenBlocksFocus">true</item> and I see that everything has to do with AppCompat (as in gradle_dependencies = 'com.android.support:appcompat-v7:26.1.0' from the buildozer.spec file perhaps?). Not sure entirely what I'm looking at in these files in my limited programming experience but maybe that gradle dependency is not working as it should?

clevermindgames commented 5 years ago

@tkuam this error basically means your build tools are incompatible with com.android.support:appcompat version. I will write up a more detailed guide how to get it to work with all the moving pieces put together in the next couple of days

tkuam commented 5 years ago

@clevermindgames okay yeah that's the conclusion I came upon after doing some googling. Thanks for working on a detailed guide. In the meantime I'll see if I can't mess around with the build tools version and get it working.

clevermindgames commented 5 years ago

@tkuam Here is the guide: http://quadropoly.com.au/kivy-and-admob-for-android-api-27/ Please let me know if it works for you. Let's discuss it there in the comments to stop hijacking this conversation :) Update: I have simplified the integration and added support for Admob Rewarded Videos if anyone is interested: https://quadropoly.com.au/kivy-and-admob-for-android-guide-part2/

Petar-Luketina commented 5 years ago

Hello, @StacyMAI! I was reading through these comments and I noticed you mention "aeabi_memclr8"

When I try to build my app, it compiles the debug APK but crashes at start. I read the logcat file and it came back with: cannot locate symbol "__aeabi_memclr8"

Would you, or anyone else, know how to fix this issue? Thank you!

inclement commented 5 years ago

@Petar-Luketina I think this issue is likely to be caused by compiling against an api level higher than your device supports. There isn't currently a good way around this, it's a bug in p4a, although there are workarounds (I think discussed earlier in this thread).

Petar-Luketina commented 5 years ago

That's better news! Thanks @inclement . Would the app work if I uploaded it on to the app store, then downloaded it on the same phone from there?

UPDATE: @inclement Hey, so I tried to upload it on the app store and there are many errors that came back from the testers. I also tried to upload it on a newer phone, and the app still crashes.

Here is the error logs from Google:

Issue: java.lang.UnsatisfiedLinkError: No implementation found for void org.libsdl.app.SDLActivity.nativeSetEnv(java.lang.String, java.lang.String) (tried Java_org_libsdl_app_SDLActivity_nativeSetEnv and Java_org_libsdl_app_SDLActivity_nativeSetEnv__Ljava_lang_String_2Ljava_lang_String_2)

Any insight?

Malakanorth commented 5 years ago

@Petar-Luketina have you tried this ? In first build with API 19, when it's good remove your dist from .buildozer/android/platforms/build/dists and re-build with API 27.

Petar-Luketina commented 5 years ago

Ah, I skimmed over the part that said to make the 19 API then delete the dists and re-build to API 27, my mistake.

It works fine on debug mode, but it's crashing when I download it from the app store. I'm going to keep working at the problem. Maybe I'm missing something else.

@StacyMAI , if I may suggest an edit though. Your above post says to change 1.5 to 1.7:

<property name="java.target" value="7" />
<property name="java.source" value="1.7" />

But I had to change both to 1.8 because that's my version of Java (that's what that number is, correct?). Perhaps suggesting either one of those two may lead the next person to less confusion.

noembryo commented 5 years ago

@Zen-CODE Any news from that VM plan of yours? :o) I'm in widows and I rely on the Kivy's android VM (v2.0) to build apks for my apps. Is the building process still more complicated that the old one, so it's not possible with a VM?

Zen-CODE commented 5 years ago

@noembryon. There is not much to more to add to it at this point. It builds for API 27 with the "API 19, clear dists, build for 27" process. I'm working on fixing that but blocked by my python-for-android service dying on imports. That's also really import to get working for us, so I'm trying to sort that out before releasing a new VM...

noembryo commented 5 years ago

@Zen-CODE Yes, I understand. Thank you for your (and the other guys) work on this. It is greatly appreciated..

atnccetti commented 5 years ago

I created a solution that at the moment makes inclusion possible, it is extremely beta, but it already works for me.

https://github.com/atnccetti/launcherKivyAndroid

Zen-CODE commented 5 years ago

@atnccetti. Thanks. There are a few issues around python services and pyjnius that I want to resolve before redoing the VM. When I get there, I'll definitely look at this. Thanks :-)

AndreMiras commented 5 years ago

Should we close that one since https://github.com/kivy/python-for-android/pull/1412 was merged?

noembryo commented 5 years ago

Does that mean that there will be a new Virtual Image for us poor windows users? ;o)

Zen-CODE commented 5 years ago

For my 2c, there are more issue around this than the python3 recipe. Python2? And until there is a buildozer.spec file that can build a python2/python3 APK from scratch, I think it best to keep it open....

RezVIKONG commented 5 years ago

Hi guys :) in the last month i built up from scratch an Ubuntu 18.10 x64 VM image with VirtualBox 5.2.22 especially for Python-for-Android builds ;) @inclement i want this project to succeed and i will try my best to play as a Beta-Tester (I'm not a pro developer, I'm just a 1st-2nd level Desktop Support & Service Desk IT technician guy...)

So here below the VM specs (full details in attachments):

As you can see from the r16b build log, i was able to make the APK (API 26, ARM64, Python3) but unfortunately my Oreo phone doesn't even let install the package (error during package analysis). I have to check more deeply the build logs...but for now i think that it's a step in the right direction :) BuildLog_NDKr16b_API26_ARM64.log BuildLog_NDKr18b_API26_ARM64.log SdkManager_list.txt PIP&PIP3_List.txt Ubuntu_APT_List.txt

Zen-CODE commented 5 years ago

@RezVIKONG. The build succeeds it seems, so the logs you've posted I don't really help us (as far as I can tell anyway). If deployment to the phone fails, we need to see why. That can (hopefully) be done by examining the output of

buildozer android debug deploy run logcat

whilst your device is connected. The output of the logcat command should indicate why the deployment fails.

Also, I would suggest continuing this discussion by posting on the kivy user group. This ticket is long and ready for closing, as support for API 26+ has been achieved.

alensiljak commented 5 years ago

Any references to "support for API 26+ has been achieved", please?

I am currently unable to build a webview bootstrap with python3 and flask, using target api 27. Also the suggestion to "build for 19" does not work since python3 recipe requires api 21+.

Thanks for all the work so far.

inclement commented 5 years ago

@MisterY p4a now properly supports different build versions in a way it didn't before, but only with the sdl2 bootstrap. The work @JonasT has been doing to unify the bootstraps has moved towards fixing this in the other ones as well (especially webview), but I don't think this particular issue is covered yet. There are a few other outstanding build target problems that I hope to look at together over Christmas.

Also the suggestion to "build for 19" does not work since python3 recipe requires api 21+.

You can just substitute 21 for 19 and it should work the same way. However, the webview bootstrap might have issues right now with the master branch so you may need to make sure your p4a is not quite up to date.

alensiljak commented 5 years ago

@inclement, thanks a lot for the tips. I'm creating a Discord account for further discussion. I'm really hoping to get at least something going and would be looking to help as much as I can.

inclement commented 5 years ago

@MisterY For what it's worth, it shouldn't be very hard to make it work.