Buildozer 编译 apk,但它在 android 上崩溃

Buildozer compiles apk, but it crashes on android(Buildozer 编译 apk,但它在 android 上崩溃)
本文介绍了Buildozer 编译 apk,但它在 android 上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够构建一个 .apk,但是在我将它安装到我的 android 手机上之后,它只是在启动时崩溃了.我失败的想法是我正在使用 3rd 方库,例如(beautifulsoup).

I am able to build an .apk, but after I install it on my android phone it simply crashes at startup. My thoughts for failing is that I am using 3rd party libraries e.g(beautifulsoup).

这就是我的导入在 main.py 中的样子:

This is how my imports look in main.py:

from kivy.app import App
from kivy.properties import ListProperty, StringProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition

import time, os, random, urllib2, re, cookielib as cj

from bs4 import BeautifulSoup as bs
from functools import partial

我在跑小牛10.9.3

I'm running mavericks 10.9.3

它与 buildozer.spec 文件有关吗?我尝试将 BeautifulSoup 添加到应用需求中,但这并没有改变任何事情.

Does it have something to do with buildozer.spec file? I've tried adding BeautifulSoup to app requirements, but it doesn't change a thing.

任何帮助将不胜感激.

推荐答案

我也遇到了这个问题,但我(显然)能够通过解决方法让一切正常工作.由于看起来您发布的不是 logcat,因此我假设您遇到了与我相同的问题.

I ran into this problem as well, but I was (apparently) able to get everything working fine with a workaround. Since it doesn't look like you posted a logcat, I'll assume you ran into the same issue I did.

是的,您确实需要在规范中将 beautifulsoup4 列为一项要求.从查看 bs4 的代码来看,bs4 似乎愿意使用几个构建器"中的任何一个.它支持 HTMLParser、html5lib 或 lxml.我不知道为什么我们不能加载 HTMLParser,但它实际上是三个库中 最不喜欢的 库,如果不是因为导入周围没有 try 块,它似乎一切都会正常工作(只要其他解析库之一可用).

Yes, you do need to list beautifulsoup4 as a requirement in your spec. From looking into bs4's code, it looks like bs4 is willing to use any of several "builders." It supports HTMLParser, html5lib, or lxml. I have no idea why we can't load HTMLParser, but it's actually the least preferred library of the three, and if it weren't for the fact that there's no try block around the import, it seems that everything would work fine (as long as one of the other parsing libraries was available).

考虑到这一点,我包含了其他库之一,并决定破解导入过程,以便 Python 假装 _htmlparser 加载正常 :)

With this in mind, I included one of the other libraries, and I decided to hack the import process so that Python would pretend _htmlparser loaded okay :)

这篇文章很有启发性:http://xion.org.pl/2012/05/06/hacking-python-imports/

最终的结果是这样的:

import imp
import sys

class ImportBlocker(object):

    def __init__(self, *args):
        self.black_list = args

    def find_module(self, name, path=None):
        if name in self.black_list:
            return self

        return None

    def load_module(self, name):
        module = imp.new_module(name)
        module.__all__ = [] # Necessary because of how bs4 inspects the module

        return module

sys.meta_path = [ImportBlocker('bs4.builder._htmlparser')]
from bs4 import BeautifulSoup

我还在 buildozer.spec 的要求中添加了 html5lib.

I also added html5lib to the requirements in buildozer.spec.

现在,这是解决问题的正确方法吗?我不知道.最好的方法可能是要求作者修复它.可能就像将导入放在 try 块中一样简单.尽管如此,这是我目前采用的方法,它至少是一个有趣的练习,也是一种测试你的应用直到出现更好的修复的方法.

Now, is this the right way to solve the problem? I don't know. The best approach would probably be to request that the author fix it. It might be as simple as to put the import in a try block. Nevertheless, this is the approach I've gone with for the moment, and it is at least an interesting exercise, and a way to test your app until a better fix comes along.

另外,我应该警告您,我最近才这样做,所以我不能 100% 保证它不会造成任何问题,但至少,它运行良好,足以让我的应用程序运行并抓取我感兴趣的特定网站.祝你好运!

Additionally, I should warn you that I only did this recently, so I can't 100% guarantee that it won't cause any problems, but at a minimum, it's worked well enough to get my app running and scraping the particular website I was interested in. Good luck!

这篇关于Buildozer 编译 apk,但它在 android 上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)