Skip to content

Port launcher to SDL2 bootstrap#891

Merged
inclement merged 12 commits intokivy:masterfrom
KeyWeeUsr:sdl2_launcher
Jan 15, 2017
Merged

Port launcher to SDL2 bootstrap#891
inclement merged 12 commits intokivy:masterfrom
KeyWeeUsr:sdl2_launcher

Conversation

@KeyWeeUsr
Copy link
Contributor

As the title says, I'm attempting to port pygame launcher to the sdl2 bootstrap. The copied files + some lines in pygame's PythonActivity.java were probably the only thing that made the launcher work. I'm not sure though and I'm not really experienced in java, so I welcome any help. ^^

}

/**
* Scans directory for a project.txt file. If it finds one,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably say android.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I only copied it from pygame bootstrap so it's even there. I'll fix it later ^^

@KeyWeeUsr
Copy link
Contributor Author

#app still named as "res/drawable/icon.png" because of incorrect xml rendering
#
V/SDL     (23650): asked to get string urlScheme
V/SDL     (23650): getting identifier
V/SDL     (23650): kind is string and name urlScheme
V/SDL     (23650): result is 2130968578
V/SDL     (23650): asked to get string appName
V/SDL     (23650): getting identifier
V/SDL     (23650): kind is string and name appName
V/SDL     (23650): result is 0
W/ResourceType(23650): No package identifier when getting value for resource number 0x00000000
V/SDL     (23650): got exception looking for string!
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/3Drendering/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/Kit/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/Miner/icon.png: open failed: ENOENT (No such file or directory)
D/dalvikvm(23650): GC_CONCURRENT freed 496K, 13% free 11615K/13348K, paused 2ms+1ms, total 25ms
D/dalvikvm(23650): WAIT_FOR_CONCURRENT_GC blocked 7ms
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/MrHyde/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/MyShowcase/icon.png: open failed: ENOENT (No such file or directory)
I/Project (23650): Couldn't open android.txt
I/Project (23650): java.io.FileNotFoundException: /storage/emulated/0/kivy/Pixel/android.txt: open f
ailed: ENOENT (No such file or directory)
I/Project (23650):      at libcore.io.IoBridge.open(IoBridge.java:409)
I/Project (23650):      at java.io.FileInputStream.<init>(FileInputStream.java:78)
I/Project (23650):      at org.kivy.android.Project.scanDirectory(Project.java:72)
I/Project (23650):      at org.kivy.android.ProjectChooser.onStart(ProjectChooser.java:56)
I/Project (23650):      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1177
)
I/Project (23650):      at android.app.Activity.performStart(Activity.java:5461)
I/Project (23650):      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2386
)
I/Project (23650):      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)

I/Project (23650):      at android.app.ActivityThread.access$900(ActivityThread.java:175)
I/Project (23650):      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
I/Project (23650):      at android.os.Handler.dispatchMessage(Handler.java:102)
I/Project (23650):      at android.os.Looper.loop(Looper.java:146)
I/Project (23650):      at android.app.ActivityThread.main(ActivityThread.java:5602)
I/Project (23650):      at java.lang.reflect.Method.invokeNative(Native Method)
I/Project (23650):      at java.lang.reflect.Method.invoke(Method.java:515)
I/Project (23650):      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.jav
a:1283)
I/Project (23650):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
I/Project (23650):      at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
I/Project (23650):      at dalvik.system.NativeStart.main(Native Method)
I/Project (23650): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or direct
ory)
I/Project (23650):      at libcore.io.Posix.open(Native Method)
I/Project (23650):      at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
I/Project (23650):      at libcore.io.IoBridge.open(IoBridge.java:393)
I/Project (23650):      ... 18 more

#
# failed loading of icons in <sdcard>/kivy? (at least it sees the folder)
#
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/SManim/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/ShopWidgets/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/T/icon.png: open failed: ENOENT (No such file or directory)
D/dalvikvm(23650): GC_FOR_ALLOC freed 190K, 13% free 11625K/13348K, paused 24ms, total 24ms
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/a/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/cgflag/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/kurtle/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/notes/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/old KivyShowcase/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/pictures/icon.png: open failed: ENOENT (No such file or directory)
E/BitmapFactory(23650): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/
kivy/showcase/icon.png: open failed: ENOENT (No such file or directory)
V/SDL     (23650): getting identifier
V/SDL     (23650): kind is layout and name project_chooser
V/SDL     (23650): result is 0
W/ResourceType(23650): No package identifier when getting value for resource number 0x00000000
D/AndroidRuntime(23650): Shutting down VM
W/dalvikvm(23650): threadid=1: thread exiting with uncaught exception (group=0x41b27c08)

#
# the file(s) were not found or whatever this means...
#
E/AndroidRuntime(23650): FATAL EXCEPTION: main
E/AndroidRuntime(23650): Process: org.test.kivylauncher, PID: 23650
E/AndroidRuntime(23650): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.test
.kivylauncher/org.kivy.android.ProjectChooser}: android.content.res.Resources$NotFoundException: Res
ource ID #0x0
E/AndroidRuntime(23650):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.j
ava:2413)
E/AndroidRuntime(23650):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.ja
va:2471)
E/AndroidRuntime(23650):        at android.app.ActivityThread.access$900(ActivityThread.java:175)
E/AndroidRuntime(23650):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:13
08)
E/AndroidRuntime(23650):        at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(23650):        at android.os.Looper.loop(Looper.java:146)
E/AndroidRuntime(23650):        at android.app.ActivityThread.main(ActivityThread.java:5602)
E/AndroidRuntime(23650):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(23650):        at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(23650):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(Zygote
Init.java:1283)
E/AndroidRuntime(23650):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
E/AndroidRuntime(23650):        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
E/AndroidRuntime(23650):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(23650): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x
0
E/AndroidRuntime(23650):        at android.content.res.Resources.getValue(Resources.java:2342)
E/AndroidRuntime(23650):        at android.content.res.Resources.loadXmlResourceParser(Resources.jav
a:3660)
E/AndroidRuntime(23650):        at android.content.res.Resources.getLayout(Resources.java:2158)
E/AndroidRuntime(23650):        at android.content.res.XResources.getLayout(XResources.java:596)
E/AndroidRuntime(23650):        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(23650):        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Na
tive Method)
E/AndroidRuntime(23650):        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBrid
ge.java:631)
E/AndroidRuntime(23650):        at android.view.LayoutInflater.inflate(Native Method)
E/AndroidRuntime(23650):        at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
E/AndroidRuntime(23650):        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Na
tive Method)
E/AndroidRuntime(23650):        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBrid
ge.java:631)
E/AndroidRuntime(23650):        at android.view.LayoutInflater.inflate(Native Method)
E/AndroidRuntime(23650):        at org.renpy.android.ResourceManager.inflateView(ResourceManager.jav
a:46)
E/AndroidRuntime(23650):        at org.kivy.android.ProjectChooser.onStart(ProjectChooser.java:64)
E/AndroidRuntime(23650):        at android.app.Instrumentation.callActivityOnStart(Instrumentation.j
ava:1177)
E/AndroidRuntime(23650):        at android.app.Activity.performStart(Activity.java:5461)
E/AndroidRuntime(23650):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.j
ava:2386)
E/AndroidRuntime(23650):        ... 12 more
W/ActivityManager( 2489):   Force finishing activity org.test.kivylauncher/org.kivy.android.ProjectC
hooser
I/WindowManager( 2489): Screenshot max retries 4 of Token{435ebe40 ActivityRecord{42b89cf8 u0 org.te
st.kivylauncher/org.kivy.android.ProjectChooser t274 f}} appWin=Window{43563560 u0 Starting org.test
.kivylauncher} drawState=4
W/WindowManager( 2489): Screenshot failure taking screenshot for (720x1280) to layer 21005
I/dumpstate(23669): begin
D/EnterpriseDeviceManager( 2489): ContainerId: 0
D/PointerIcon( 2489): setMouseIconStyle1 pointerType: 1001iconType:101 flag:0
D/PointerIcon( 2489): setMouseCustomIcon IconType is same.101
D/PointerIcon( 2489): setHoveringSpenIconStyle1 pointerType: 10001iconType:1 flag:0
D/PointerIcon( 2489): setHoveringSpenCustomIcon IconType is same.1
D/CrashAnrDetector( 2489): processName: org.test.kivylauncher
D/STATUSBAR-StatusBarManagerService( 2489): manageDisableList what=0x0 pkg=WindowManager.LayoutParam
s
D/CrashAnrDetector( 2489): broadcastEvent : org.test.kivylauncher data_app_crash
W/ContextImpl( 2489): Calling a method in the system process without a qualified user: android.app.C
ontextImpl.sendBroadcast:1523 com.android.server.analytics.data.collection.application.CrashAnrDetec
tor.broadcastEvent:296 com.android.server.analytics.data.collection.application.CrashAnrDetector.pro
cessDropBoxEntry:254 com.android.server.analytics.data.collection.application.CrashAnrDetector.acces
s$100:60 com.android.server.analytics.data.collection.application.CrashAnrDetector$1.onReceive:102

Logcat, if anybody is interested. The java activity copied from pygame crashes, so this will probably take a while for me. I hope it's only path issue. But anyway, the build is fixed, the all necessary files should be already there and I don't see other annoying to fix stuff. 🍡 so... yeah Java.

@KeyWeeUsr
Copy link
Contributor Author

I'll do little changes and it's ready ^^

@KeyWeeUsr
Copy link
Contributor Author

KeyWeeUsr commented Oct 8, 2016

The tests need #896 or an alternative to allow --launcher switch for the build and #898. Is able to run Showcase, Pictures, haven't tried anything else.

Please review it or even try with python3. It'll most likely work. 🍡

@inclement
Copy link
Member

Looks good at a quick check, nice work! The launcher testapps are a particularly nice touch :)

I'll test it properly sometime in the next few days.

@KeyWeeUsr
Copy link
Contributor Author

KeyWeeUsr commented Oct 9, 2016

I've tested it and it should be ready, but there are some things that worry me:

  1. Images Some images (.png of what I saw) aren't loaded properly for unknown reason (as seen on the screenshot vs original). The only log I got is [ERROR] and that the image couldn't be loaded.
  2. python 3 support doesn't seem to work as some recipes expect python3 and some python3crystax, which resulted in conflicts for me and didn't even start building.

I'd appreciate any pointings on what is where broken or how to get the python header into the tar.


How to test:
git clone -b sdl2_launcher https://github.com/KeyWeeUsr/python-for-android && cd python-for-android
(sudo) pip install .
python testapps/testlauncher_setup/sdl2.py apk
Put apps into /sdcard/kivy/ as it's stated in the docs.

@KeyWeeUsr
Copy link
Contributor Author

KeyWeeUsr commented Nov 4, 2016

Py3 attempt still fails due to collision:

running apk
[INFO]:    Will compile for the following archs: armeabi
[INFO]:    Getting Android API version from user argument
[INFO]:    Available Android APIs are (8, 10, 14, 19)
[INFO]:    Requested API target 14 is available, continuing.
[INFO]:    Found NDK dir in $ANDROIDNDK
[INFO]:    Got NDK version from $ANDROIDNDKVER
[INFO]:    Using Crystax NDK 10.3.2
[INFO]:    Found virtualenv at /usr/local/bin/virtualenv
[INFO]:    Found the following toolchain versions: ['4.9', '5', 'clang3.6', 'clang3.7']
[INFO]:    Picking the latest gcc toolchain, here 5
[INFO]:    No existing dists meet the given requirements!
[INFO]:    No dist exists that meets your requirements, so one will be built.
[INFO]:    Bootstrap requires recipes ['sdl2', ('python2', 'python3crystax')]
[INFO]:    No recipe named lxml; will attempt to install with pip
[INFO]:    Loaded recipe pil (depends on [('python2', 'python3'), 'png', 'jpeg'])
[INFO]:    Loaded recipe sdl2 (depends on [('python2', 'python3crystax'), 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf'], conflicts ['sdl', 'pygame', 'pygame_bootstrap_components'])
[INFO]:    Loaded recipe twisted (depends on ['zope_interface', ('python2', 'python3crystax'), 'setuptools'])
[INFO]:    No recipe named docutils; will attempt to install with pip
[INFO]:    No recipe named pygments; will attempt to install with pip
[INFO]:    No recipe named plyer; will attempt to install with pip
[INFO]:    Loaded recipe cymunk (depends on [('python2', 'python3'), ('python2', 'python3crystax')])
[INFO]:    Loaded recipe kivy (depends on ['pyjnius', ('sdl2', 'pygame'), ('python2', 'python3crystax')])
[INFO]:    Loaded recipe sqlite3 (depends on [])
[INFO]:    Loaded recipe pyjnius (depends on ['six', ('sdl2', 'sdl', 'genericndkbuild'), ('python2', 'python3crystax')])
[INFO]:    Loaded recipe python3 (depends on ['hostpython3'], conflicts ['python2'])
[INFO]:    Loaded recipe png (depends on [])
[INFO]:    Loaded recipe jpeg (depends on [])
[INFO]:    Loaded recipe sdl2_image (depends on [])
[INFO]:    Loaded recipe sdl2_mixer (depends on [])
[INFO]:    Loaded recipe sdl2_ttf (depends on [])
[INFO]:    Loaded recipe zope_interface (depends on ['python2'])
[INFO]:    Loaded recipe setuptools (depends on ['python2'])
[INFO]:    Loaded recipe six (depends on [('python2', 'python3crystax')])
[INFO]:    Loaded recipe hostpython3 (depends on [], conflicts ['hostpython2'])
[INFO]:    Loaded recipe python2 (depends on ['hostpython2'], conflicts ['python3crystax', 'python3'])
[WARNING]: python2 conflicts with python3crystax, but both have been included or pulled into the requirements.
[WARNING]: Due to this conflict the build cannot continue, exiting.

The missing pngs had only a slightest difference between logs when ran as casual app and via launcher:

I/python  (16400): [INFO   ] [GL          ] NPOT texture support is available
I/python  (16400): [WARNING] [GL          ] Unpack subimage support is not available

both cases had loaded this in the beginning, so I'm really curious what's going on:

D/libEGL  (16400): loaded /system/lib/egl/libEGL_mali.so
D/libEGL  (16400): loaded /system/lib/egl/libGLESv1_CM_mali.so
D/libEGL  (16400): loaded /system/lib/egl/libGLESv2_mali.so

@KeyWeeUsr
Copy link
Contributor Author

KeyWeeUsr commented Nov 4, 2016

Scratch that png bug. It's a Kivy bug, mainly related to kv files - it's about finding the files with path source: 'file.ext'. Sometimes this pops out on reddit or at SO, I usually fix it with putting os.path.dirname(os.path.abspath(__file__)) into App class and access it through kv file. I haven't edited some of my older files with such a fix, therefore I thought it's just broken for the launcher and probably some path/recipe issue.

Also the black in the presplash was bad, I could see the presplash image popping out from darkness even with a screen filter, so I cut the rocket out and put into the casual app's presplash. It's even more consistent now 😋

So... the launcher is finally back and kicking 🍡

image

@KeyWeeUsr
Copy link
Contributor Author

KeyWeeUsr commented Dec 3, 2016

I kind of forgot to include the change about orientation, now it's here. Also, there's this thing that ANDROID_APP_PATH is a critical variable for basically anything related to kivy and for the launcher itself.

If we run with ANDROID_APP_PATH holding a value of data/data/org.something/files or similar, it will run main.py because of the previous changes(ANDROID_ENTRYPOINT), but it'll run it as if it was in data/data/org.something/files, therefore:

  • kivy would be logged in that folder, not in sdcard/kivy/<app>
  • images wouldn't load, see previous issue with pngs above
  • anything requested via relative path through python will be fetched from that path - isn't editable by non-root user

and other stuff. Loading of libraries such as here should target only variables that if changed will break everything and won't allow python program to run, such as PYTHON* variables, or probably even ANDROID_PRIVATE otherwise it won't work in launcher itself.

Anything else non-related to launcher should work just fine.

If only Project*.java is used, it discards even Project.java, which results in 'not found' in PythonActivity.java and stops compilation. Same thing will happen if you try to separate it to a package (org.kivy.launcher), but with more pain while trying to fix it.
basically creating .kivy folder(logs), fetching files with paths relative to main.py and so on. ANDROID_APP_PATH has to be the folder of main.py file.
@inclement inclement merged commit 2004698 into kivy:master Jan 15, 2017
@inclement
Copy link
Member

Looks good, thanks a lot!

@KeyWeeUsr KeyWeeUsr deleted the sdl2_launcher branch December 8, 2018 08:17
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

Successfully merging this pull request may close these issues.

3 participants