Checkout Kivy. They have done a really great job so far, and I am a big fan of their work. It is still lacking some providers, but they keep adding new stuff to it everyday. First thing you need to do is to check your requirement against what they can offer based on their documentation. They have create an amazing framework for input such as multi-touch or pen handling. They use OpenGL ES internally, as a result complex graphics and visualizations can run very fast when interacting with the the application. Their process for creating an apk is also very straight forward.
Edit: This is not Kivy, this is a seperate project, intended to be a toolchain usable for other toolkit. The architecture is modular, and you can include new recipe for including new python extensions (as brew, macports, cygwin etc.).
Edit:
Ok, after comments:
I haven’t read the question properly. No you can’t write write proper, full fledged apps for Android, but anyway check ASE. It is really cool project.
However webview just display them as literal strings. Here are the result:
Edit: I add original string returned from server side:
“<!DOCTYPE html> <html
lang="en"> <head> <meta
charset="utf-8"> <meta
http-equiv="X-UA-Compatible"
content="IE=edge"> <meta
name="viewport"
content="width=device-width,
initial-scale=1.0"> <meta
name="description"
content="">
<title>Saulify</title> <!– All the
Favicons… –> <link rel="shortcut
icon"
href="/static/favicon/favicon.ico">
<link rel="apple-touch-icon"
sizes="57×57"
href="/static/favicon/apple-touch-icon-57×57.png">
<link rel="apple-touch-icon"
sizes="114×114"
href="/static/favicon/apple-touch-icon-114×114.png">
<link rel="apple-touch-icon"
sizes="72×72"
href="/static/favicon/apple-touch-icon-72×72.png">
<link rel="apple-touch-icon"
sizes="144×144"
href="/static/favicon/apple-touch-icon-144×144.png">
<link rel="apple-touch-icon"
sizes="60×60"
href="/static/favicon/apple-touch-icon-60×60.png">
<link rel="apple-touch-icon"
sizes="120×120"
href="/static/favicon/apple-touch-icon-120×120.png">
<link rel="apple-touch-icon"
sizes="76×76"
href="/static/favicon/apple-touch-icon-76×76.png">
<link rel="apple-touch-icon"
sizes="152×152"
href="/static/favicon/apple-touch-icon-152×152.png">
<link rel="apple-touch-icon"
sizes="180×180"
href="/static/favicon/apple-touch-icon-180×180.png">
<link rel="icon"
type="image/png"
href="/static/favicon/favicon-192×192.png"
sizes="192×192"> <link
rel="icon" type="image/png"
href="/static/favicon/favicon-160×160.png"
sizes="160×160"> <link
rel="icon" type="image/png"
href="/static/favicon/favicon-96×96.png"
sizes="96×96"> <link
rel="icon" type="image/png"
href="/static/favicon/favicon-16×16.png"
sizes="16×16"> <link
rel="icon" type="image/png"
href="/static/favicon/favicon-32×32.png"
sizes="32×32"> <meta
name="msapplication-TileColor"
content="#da532c"> <meta
name="msapplication-TileImage"
content="/static/favicon/mstile-144×144.png">
<meta name="msapplication-config"
content="/static/favicon/browserconfig.xml">
<!– External CSS –> <link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!– External Fonts –> <link
href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"
rel="stylesheet"> <link
href='//fonts.googleapis.com/css?family=Open+Sans:300,600'
rel='stylesheet'
type='text/css'> <link
href='//fonts.googleapis.com/css?family=Lora:400,700'
rel='stylesheet'
type='text/css'> <!–[if lt IE
9]> <script
src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script
src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]–> <!– Site CSS –>
<link rel="stylesheet"
type="text/css"
href="/static/css/style.css"> <link
rel="stylesheet" type="text/css"
href="/static/css/glyphicon.css">
</head> <body> <div
class="container article-page"> <div
class="row"> <div
class="col-md-8 col-md-offset-2">
<h2><a
href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">Gov.
Jerry Brown Says Ted Cruz Is &#39;Absolutely
Unfit&#39; To Run For Office Because Of Climate Change
Views</a></h2> <h4>Sam
Levine</h4> <div
class="article"> <p>California
Gov. Jerry Brown (D) said on Sunday that Texas Sen. Ted Cruz (R-Texas)
is "absolutely unfit to be running for office"
because of his position on climate change.</p>
<p>"I just came back from New Hampshire, where
there's snow and ice everywhere. My view on this is simple:
Debates on this should follow science and should follow data, and many
of the alarmists on global warming, they have a problem because the
science doesn't back them up," Cruz <a
href="https://www.youtube.com/watch?v=m0UJ_Sc0Udk">said</a>
on "Late Night with Seth Meyers" last
week.</p> <p>To back up his claim, Cruz
cited satellite data that has shown a lack of significant warming over
the last 17 years. But Cruz's reasoning <a
href="http://www.politifact.com/truth-o-meter/statements/2015/mar/20
/ted-cruz/ted-cruzs-worlds-fire-not-last-17-years/">has
been debunked by Politifact</a>, which has shown that
scientists have ample evidence to believe that the climate will
continue to warm.</p> <p>"What he
said is absolutely false,” Brown said on <a
href="http://www.nbcnews.com/meet-the-press/california-governor-ted-cruz-
unfit-be-running-n328046">NBC's
"Meet the Press."</a> He added that
<a
href="http://climate.nasa.gov/scientific-consensus/">over
90 percent</a> of scientists who study the climate agree
that climate change is caused by human activity. "That man
betokens such a level of ignorance and a direct falsification of
existing scientific data. It's shocking, and I think that man
has rendered himself absolutely unfit to be running for
office," Brown said.</p> <p>Brown
added that climate change has <a
href="http://www.huffingtonpost.com/2015/03/06/california-drought-february-
record_n_6820704.html?utm_hp_ref=california-drought">caused
droughts in his state</a>, as well as severe cold and
storms on the east coast.</p> <p>While
Cruz may have seen snow and ice everywhere in New Hampshire, data
shows that the country is actually experiencing a <a
href="http://www.huffingtonpost.com/2015/02/19/cold-weather-
winter_n_6713104.html">warmer than
average</a> winter.</p>
<p>Brown’s criticism of Cruz comes one day before the
Texas senator is set to announce a <a
href="http://www.huffingtonpost.com/2015/03/22
/ted-cruz-2016_n_6917824.html">presidential
campaign</a>. </p> </div>
<div class="original"> <a
href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">VIEW
ORIGINAL</a> </div> </div>
</div> </div> <script
src="//code.jquery.com/jquery-latest.js"></script>
<script
src="/static/js/modal.js"></script>
<script
src="/static/js/bootbox.min.js"></script>
<script
src="/static/js/site.js"></script> <script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-56257533-1',
'auto'); ga('send',
'pageview'); </script>
</body> </html>”
回答 0
我在这里修改了代码:
public classtestextendsActivity {privateWebViewwv;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.test);wv = (WebView) findViewById(R.id.wv);Strings = "<!DOCTYPEhtml> <htmllang="en"> <head> <metacharset="utf-8"> <metahttp-equiv="X-UA-Compatible" content="IE=edge"> <metaname="viewport" content="width=device-width, initial-scale=1.0"> <metaname="description" content=""> <title>Saulify</title> <!-- AlltheFavicons... --> <linkrel="shortcuticon" href="/static/favicon/favicon.ico"> <linkrel="apple-touch-icon" sizes="57x57" href="/static/favicon/apple-touch-icon-57x57.png"> <linkrel="apple-touch-icon" sizes="114x114" href="/static/favicon/apple-touch-icon-114x114.png"> <linkrel="apple-touch-icon" sizes="72x72" href="/static/favicon/apple-touch-icon-72x72.png"> <linkrel="apple-touch-icon" sizes="144x144" href="/static/favicon/apple-touch-icon-144x144.png"> <linkrel="apple-touch-icon" sizes="60x60" href="/static/favicon/apple-touch-icon-60x60.png"> <linkrel="apple-touch-icon" sizes="120x120" href="/static/favicon/apple-touch-icon-120x120.png"> <linkrel="apple-touch-icon" sizes="76x76" href="/static/favicon/apple-touch-icon-76x76.png"> <linkrel="apple-touch-icon" sizes="152x152" href="/static/favicon/apple-touch-icon-152x152.png"> <linkrel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon-180x180.png"> <linkrel="icon" type="image/png" href="/static/favicon/favicon-192x192.png" sizes="192x192"> <linkrel="icon" type="image/png" href="/static/favicon/favicon-160x160.png" sizes="160x160"> <linkrel="icon" type="image/png" href="/static/favicon/favicon-96x96.png" sizes="96x96"> <linkrel="icon" type="image/png" href="/static/favicon/favicon-16x16.png" sizes="16x16"> <linkrel="icon" type="image/png" href="/static/favicon/favicon-32x32.png" sizes="32x32"> <metaname="msapplication-TileColor" content="#da532c"> <metaname="msapplication-TileImage" content="/static/favicon/mstile-144x144.png"> <metaname="msapplication-config" content="/static/favicon/browserconfig.xml"> <!-- ExternalCSS --> <linkrel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <!-- External Fonts --> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <link href='//fonts.googleapis.com/css?family=Open+Sans:300,600' rel='stylesheet' type='text/css'> <link href='//fonts.googleapis.com/css?family=Lora:400,700' rel='stylesheet' type='text/css'> <!--[if lt IE 9]> <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <!-- Site CSS --> <link rel="stylesheet" type="text/css" href="/static/css/style.css"> <link rel="stylesheet" type="text/css" href="/static/css/glyphicon.css"> </head> <body> <div class="container article-page"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <h2><a href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">Gov. Jerry Brown Says Ted Cruz Is &#39;Absolutely Unfit&#39; To Run For Office Because Of Climate Change Views</a></h2> <h4>Sam Levine</h4> <div class="article"> <p>California Gov. Jerry Brown (D) said on Sunday that Texas Sen. Ted Cruz (R-Texas) is "absolutely unfit to be running for office" because of his position on climate change.</p> <p>"I just came back from New Hampshire, where there's snow and ice everywhere. My view on this is simple: Debates on this should follow science and should follow data, and many of the alarmists on global warming, they have a problem because the science doesn't back them up," Cruz <a href="https://www.youtube.com/watch?v=m0UJ_Sc0Udk">said</a> on "Late Night with Seth Meyers" last week.</p> <p>To back up his claim, Cruz cited satellite data that has shown a lack of significant warming over the last 17 years. But Cruz's reasoning <a href="http://www.politifact.com/truth-o-meter/statements/2015/mar/20 /ted-cruz/ted-cruzs-worlds-fire-not-last-17-years/">has been debunked by Politifact</a>, which has shown that scientists have ample evidence to believe that the climate will continue to warm.</p> <p>"What he said is absolutely false,” Brown said on <a href="http://www.nbcnews.com/meet-the-press/california-governor-ted-cruz- unfit-be-running-n328046">NBC's "Meet the Press."</a> He added that <a href="http://climate.nasa.gov/scientific-consensus/">over 90 percent</a> of scientists who study the climate agree that climate change is caused by human activity. "That man betokens such a level of ignorance and a direct falsification of existing scientific data. It's shocking, and I think that man has rendered himself absolutely unfit to be running for office," Brown said.</p> <p>Brown added that climate change has <a href="http://www.huffingtonpost.com/2015/03/06/california-drought-february- record_n_6820704.html?utm_hp_ref=california-drought">caused droughts in his state</a>, as well as severe cold and storms on the east coast.</p> <p>While Cruz may have seen snow and ice everywhere in New Hampshire, data shows that the country is actually experiencing a <a href="http://www.huffingtonpost.com/2015/02/19/cold-weather- winter_n_6713104.html">warmer than average</a> winter.</p> <p>Brown’s criticism of Cruz comes one day before the Texas senator is set to announce a <a href="http://www.huffingtonpost.com/2015/03/22 /ted-cruz-2016_n_6917824.html">presidential campaign</a>. </p> </div> <div class="original"> <a href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">VIEW ORIGINAL</a> </div> </div> </div> </div> <script src="//code.jquery.com/jquery-latest.js"></script> <script src="/static/js/modal.js"></script> <script src="/static/js/bootbox.min.js"></script> <script src="/static/js/site.js"></script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-56257533-1', 'auto'); ga('send', 'pageview'); </script> </body> </html>";
wv.loadData(stripHtml(s), "text/html", "UTF-8");
}
public String stripHtml(String html) {
return Html.fromHtml(html).toString();
}
}
public class test extends Activity {
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
wv = (WebView) findViewById(R.id.wv);
String s = "<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <title>Saulify</title> <!-- All the Favicons... --> <link rel="shortcut icon" href="/static/favicon/favicon.ico"> <link rel="apple-touch-icon" sizes="57x57" href="/static/favicon/apple-touch-icon-57x57.png"> <link rel="apple-touch-icon" sizes="114x114" href="/static/favicon/apple-touch-icon-114x114.png"> <link rel="apple-touch-icon" sizes="72x72" href="/static/favicon/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="144x144" href="/static/favicon/apple-touch-icon-144x144.png"> <link rel="apple-touch-icon" sizes="60x60" href="/static/favicon/apple-touch-icon-60x60.png"> <link rel="apple-touch-icon" sizes="120x120" href="/static/favicon/apple-touch-icon-120x120.png"> <link rel="apple-touch-icon" sizes="76x76" href="/static/favicon/apple-touch-icon-76x76.png"> <link rel="apple-touch-icon" sizes="152x152" href="/static/favicon/apple-touch-icon-152x152.png"> <link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon-180x180.png"> <link rel="icon" type="image/png" href="/static/favicon/favicon-192x192.png" sizes="192x192"> <link rel="icon" type="image/png" href="/static/favicon/favicon-160x160.png" sizes="160x160"> <link rel="icon" type="image/png" href="/static/favicon/favicon-96x96.png" sizes="96x96"> <link rel="icon" type="image/png" href="/static/favicon/favicon-16x16.png" sizes="16x16"> <link rel="icon" type="image/png" href="/static/favicon/favicon-32x32.png" sizes="32x32"> <meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-TileImage" content="/static/favicon/mstile-144x144.png"> <meta name="msapplication-config" content="/static/favicon/browserconfig.xml"> <!-- External CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <!-- External Fonts --> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <link href='//fonts.googleapis.com/css?family=Open+Sans:300,600' rel='stylesheet' type='text/css'> <link href='//fonts.googleapis.com/css?family=Lora:400,700' rel='stylesheet' type='text/css'> <!--[if lt IE 9]> <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <!-- Site CSS --> <link rel="stylesheet" type="text/css" href="/static/css/style.css"> <link rel="stylesheet" type="text/css" href="/static/css/glyphicon.css"> </head> <body> <div class="container article-page"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <h2><a href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">Gov. Jerry Brown Says Ted Cruz Is &#39;Absolutely Unfit&#39; To Run For Office Because Of Climate Change Views</a></h2> <h4>Sam Levine</h4> <div class="article"> <p>California Gov. Jerry Brown (D) said on Sunday that Texas Sen. Ted Cruz (R-Texas) is "absolutely unfit to be running for office" because of his position on climate change.</p> <p>"I just came back from New Hampshire, where there's snow and ice everywhere. My view on this is simple: Debates on this should follow science and should follow data, and many of the alarmists on global warming, they have a problem because the science doesn't back them up," Cruz <a href="https://www.youtube.com/watch?v=m0UJ_Sc0Udk">said</a> on "Late Night with Seth Meyers" last week.</p> <p>To back up his claim, Cruz cited satellite data that has shown a lack of significant warming over the last 17 years. But Cruz's reasoning <a href="http://www.politifact.com/truth-o-meter/statements/2015/mar/20 /ted-cruz/ted-cruzs-worlds-fire-not-last-17-years/">has been debunked by Politifact</a>, which has shown that scientists have ample evidence to believe that the climate will continue to warm.</p> <p>"What he said is absolutely false,” Brown said on <a href="http://www.nbcnews.com/meet-the-press/california-governor-ted-cruz- unfit-be-running-n328046">NBC's "Meet the Press."</a> He added that <a href="http://climate.nasa.gov/scientific-consensus/">over 90 percent</a> of scientists who study the climate agree that climate change is caused by human activity. "That man betokens such a level of ignorance and a direct falsification of existing scientific data. It's shocking, and I think that man has rendered himself absolutely unfit to be running for office," Brown said.</p> <p>Brown added that climate change has <a href="http://www.huffingtonpost.com/2015/03/06/california-drought-february- record_n_6820704.html?utm_hp_ref=california-drought">caused droughts in his state</a>, as well as severe cold and storms on the east coast.</p> <p>While Cruz may have seen snow and ice everywhere in New Hampshire, data shows that the country is actually experiencing a <a href="http://www.huffingtonpost.com/2015/02/19/cold-weather- winter_n_6713104.html">warmer than average</a> winter.</p> <p>Brown’s criticism of Cruz comes one day before the Texas senator is set to announce a <a href="http://www.huffingtonpost.com/2015/03/22 /ted-cruz-2016_n_6917824.html">presidential campaign</a>. </p> </div> <div class="original"> <a href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">VIEW ORIGINAL</a> </div> </div> </div> </div> <script src="//code.jquery.com/jquery-latest.js"></script> <script src="/static/js/modal.js"></script> <script src="/static/js/bootbox.min.js"></script> <script src="/static/js/site.js"></script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-56257533-1', 'auto'); ga('send', 'pageview'); </script> </body> </html>";
wv.loadData(stripHtml(s), "text/html", "UTF-8");
}
public String stripHtml(String html) {
return Html.fromHtml(html).toString();
}
}
回答 1
试试这个代码,
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N){
yourtextview.setText(Html.fromHtml(yourstring,Html.FROM_HTML_MODE_LEGACY));
}
else {
yourtextview.setText(Html.fromHtml(yourstring));
}
I would like to develop a (rather simple) android app to be distributed via Play Store. I would like to do so completely in python. However, the online research hasn’t quite enlightened me: most comments are either outdated (>1 year old, and I feel there might be better integration of python since then) or they talk about running python in android (e.g. here).
Therefore, I’m looking for information regarding the questions:
is it feasible to develop an App completely in python – and what are the tools to do so? (Is e.g. Kivy recommendable?)
if so: what are the best software environments to implement this? (I unsuccessfully tried using Android Studio but couldn’t figure out a way to run python code there.)
I’m quite new to app development and would highly appreciate any leads of doing this in python rather than in Jave etc., which I don’t know yet.
To answer your first question: yes it is feasible to develop an android application in pure python, in order to achieve this I suggest you use BeeWare, which is just a suite of python tools, that work together very well and they enable you to develop platform native applications in python.
checkout this video by the creator of BeeWare that perfectly explains and demonstrates it’s application
How it works
Android’s preferred language of implementation is Java – so if you want to write an Android application in Python, you need to have a way to run your Python code on a Java Virtual Machine. This is what VOC does. VOC is a transpiler – it takes Python source code, compiles it to CPython Bytecode, and then transpiles that bytecode into Java-compatible bytecode. The end result is that your Python source code files are compiled directly to a Java .class file, which can be packaged into an Android application.
VOC also allows you to access native Java objects as if they were Python objects, implement Java interfaces with Python classes, and subclass Java classes with Python classes. Using this, you can write an Android application directly against the native Android APIs.
Once you’ve written your native Android application, you can use Briefcase to package your Python code as an Android application.
Briefcase is a tool for converting a Python project into a standalone native application. You can package projects for:
Mac
Windows
Linux
iPhone/iPad
Android
AppleTV
tvOS.
You can check This native Android Tic Tac Toe app written in Python, using the BeeWare suite. on GitHub
in addition to the BeeWare tools, you’ll need to have a JDK and Android SDK installed to test run your application.
and to answer your second question: a good environment can be anything you are comfortable with be it a text editor and a command line, or an IDE, if you’re looking for a good python IDE I would suggest you try Pycharm, it has a community edition which is free, and it has a similar environment as android studio, due to to the fact that were made by the same company.
You could try BeeWare – as described on their website:
Write your apps in Python and release them on iOS, Android, Windows, MacOS, Linux, Web, and tvOS using rich, native user interfaces. One codebase. Multiple apps.
Gives you want you want now to write Android Apps in Python, plus has the advantage that you won’t need to learn yet another framework in future if you end up also wanting to do something on one of the other listed platforms.
This integrates with the Android build system, it provides a Python API for all android features. To quote the site “The complete Android API and user interface toolkit are directly at your disposal.”
This provides a multi target transpiler, supports many targets such as Android and iOS. It uses a generic widget toolkit (toga) that maps to the host interface calls.
Which One?
Both are active projects and their github accounts shows a fair amount of recent activity.
Beeware Toga like all widget libraries is good for getting the basics out to multiple platforms. If you have basic designs, and a desire to expand to other platforms this should work out well for you.
On the other hand, Chaquopy is a much more precise in its mapping of the python API to Android. It also allows you to mix in Java, useful if you want to use existing code from other resources. If you have strict design targets, and predominantly want to target Android this is a much better resource.
When I saw these two keywords together in your question, Kivy is the one which came to my mind first.
Before coming to native Android development in Java using Android Studio, I had tried Kivy. It just awesome. Here are a few advantage I could find out.
Simple to use
With a python basics, you won’t have trouble learning it.
Good community
It’s well documented and has a great, active community.
Cross platform.
You can develop thing for Android, iOS, Windows, Linux and even Raspberry Pi with this single framework.
Open source.
It is a free software
At least few of it’s (Cross platform) competitors want you to pay a fee if you want a commercial license.
Accelerated graphics support
Kivy‘s graphics engine build over OpenGL ES 2 makes it suitable for softwares which require fast graphics rendering such as games.
Now coming into the next part of question, you can’t use Android Studio IDE for Kivy. Here is a detailed guide for setting up the development environment.
/code Source code
/contrib Third-party libraries
/doc Documentation (doxysource and pre-compiled docs)
/include Public header C and C++ header files
/scripts Scripts used to generate the loading code for some formats
/port Ports to other languages and scripts to maintain those.
/test Unit- and regression tests, test suite of models
/tools Tools (old assimp viewer, command line `assimp`)
/samples A small number of samples to illustrate possible
use cases for Assimp
源代码的组织方式如下:
code/Common The base implementation for importers and the infrastructure
code/PostProcessing The post-processing steps
code/AssetLib/<FormatName> Implementation for import and export for the format
Pygame is a 2D game engine for Python (on desktop) that is popular with new programmers. The Pygame Subset for Android describes itself as…
…a port of a subset of Pygame functionality to the Android platform. The goal of the project is to allow the creation of Android-specific games, and to ease the porting of games from PC-like platforms to Android.
The examples include a complete game packaged as an APK, which is pretty interesting.
I’ve also open sourced Ignifuga, my 2D Game Engine. It’s Python/SDL based, and it cross compiles for Android. Even if you don’t use it for games, you might get useful ideas from the code or builder utility (named Schafer, after Tim… you know who).
SL4A does what you want. You can easily install it directly onto your device from their site, and do not need root.
It supports a range of languages. Python is the most mature. By default, it uses Python 2.6, but there is a 3.2 port you can use instead. I have used that port for all kinds of things on a Galaxy S2 and it worked fine.
API
SL4A provides a port of their android library for each supported language. The library provides an interface to the underlying Android API through a single Android object.
from android import Android
droid = Android()
droid.ttsSpeak('hello world') # example using the text to speech facade
Each language has pretty much the same API. You can even use the JavaScript API inside webviews.
let droid = new Android();
droid.ttsSpeak("hello from js");
User Interfaces
For user interfaces, you have three options:
You can easily use the generic, native dialogues and menus through the
API. This is good for confirmation dialogues and other basic user inputs.
You can also open a webview from inside a Python script, then use HTML5
for the user interface. When you use webviews from Python, you can pass
messages back and forth, between the webview and the Python process that
spawned it. The UI will not be native, but it is still a good option to
have.
There is some support for native Android user interfaces, but I am not
sure how well it works; I just haven’t ever used it.
You can mix options, so you can have a webview for the main interface, and still use native dialogues.
QPython
There is a third party project named QPython. It builds on SL4A, and throws in some other useful stuff.
QPython gives you a nicer UI to manage your installation, and includes a little, touchscreen code editor, a Python shell, and a PIP shell for package management. They also have a Python 3 port. Both versions are available from the Play Store, free of charge. QPython also bundles libraries from a bunch of Python on Android projects, including Kivy, so it is not just SL4A.
Note that QPython still develop their fork of SL4A (though, not much to be honest). The main SL4A project itself is pretty much dead.
As a Python lover and Android programmer, I’m sad to say this is not a good way to go. There are two problems:
One problem is that there is a lot more than just a programming language to the Android development tools. A lot of the Android graphics involve XML files to configure the display, similar to HTML. The built-in java objects are integrated with this XML layout, and it’s a lot easier than writing your code to go from logic to bitmap.
The other problem is that the G1 (and probably other Android devices for the near future) are not that fast. 200 MHz processors and RAM is very limited. Even in Java, you have to do a decent amount of rewriting-to-avoid-more-object-creation if you want to make your app perfectly smooth. Python is going to be too slow for a while still on mobile devices.
I wanted to add to what @JohnMudd has written about Kivy. It has been years since the situation he described, and Kivy has evolved substantially.
The biggest selling point of Kivy, in my opinion, is its cross-platform compatibility. You can code and test everything using any desktop environment (Windows/*nix etc.), then package your app for a range of different platforms, including Android, iOS, MacOS and Windows (though apps often lack the native look and feel).
With Kivy’s own KV language, you can code and build the GUI interface easily (it’s just like Java XML, but rather than TextView etc., KV has its own ui.widgets for a similar translation), which is in my opinion quite easy to adopt.
Currently Buildozer and python-for-android are the most recommended tools to build and package your apps. I have tried them both and can firmly say that they make building Android apps with Python a breeze. Their guides are well documented too.
iOS is another big selling point of Kivy. You can use the same code base with few changes required via kivy-ios Homebrew tools, although Xcode is required for the build, before running on their devices (AFAIK the iOS Simulator in Xcode currently doesn’t work for the x86-architecture build). There are also some dependency issues which must be manually compiled and fiddled around with in Xcode to have a successful build, but they wouldn’t be too difficult to resolve and people in Kivy Google Group are really helpful too.
With all that being said, users with good Python knowledge should have no problem picking up the basics quickly.
If you are using Kivy for more serious projects, you may find existing modules unsatisfactory. There are some workable solutions though. With the (work in progress) pyjnius for Android, and pyobjus, users can now access Java/Objective-C classes to control some of the native APIs.
Not at the moment and you would be lucky to get Jython to work soon. If you’re planning to start your development now you would be better off with just sticking to Java for now on.
Using SL4A (which has already been mentioned by itself in other answers) you can run a full-blown web2py instance (other python web frameworks are likely candidates as well). SL4A doesn’t allow you to do native UI components (buttons, scroll bars, and the like), but it does support WebViews. A WebView is basically nothing more than a striped down web browser pointed at a fixed address. I believe the native Gmail app uses a WebView instead of going the regular widget route.
This route would have some interesting features:
In the case of most python web frameworks, you could actually develop and test without using an android device or android emulator.
Whatever Python code you end up writing for the phone could also be put on a public webserver with very little (if any) modification.
You could take advantage of all of the crazy web stuff out there: query, HTML5, CSS3, etc.
I use the QPython app. It’s free and includes a code editor, an interactive interpreter and a package manager, allowing you to create and execute Python programs directly on your device.
Python for android is a project to create your own Python distribution including the modules you want, and create an apk including python, libs, and your application.
Chaquopy is a plugin for Android Studio’s Gradle-based build system. It focuses on close integration with the standard Android development tools.
It provides complete APIs to call Java from Python or Python from Java, allowing the developer to use whichever language is best for each component of their app.
It can automatically download PyPI packages and build them into an app, including selected native packages such as NumPy.
It enables full access to all Android APIs from Python, including the native user interface toolkit (example pure-Python activity).
This is a commercial product, but it’s free for open-source use and will always remain that way.
The Scripting Layer for Android, SL4A, is an open source application that allows programs written in a range of interpreted languages to run on Android. It also provides a high level API that allows these programs to interact with the Android device, making it easy to do stuff like accessing sensor data, sending an SMS, rendering user interfaces and so on.
python-for-android is an open source build tool to let you package Python code into standalone android APKs. These can be passed around, installed, or uploaded to marketplaces such as the Play Store just like any other Android app. This tool was originally developed for the Kivy cross-platform graphical framework, but now supports multiple bootstraps and can be easily extended to package other types of Python apps for Android.
BeeWare allows you to write your app in Python and release it on multiple platforms. No need to rewrite the app in multiple programming languages. It means no issues with build tools, environments, compatibility, etc.
The Scripting Layer for Android, SL4A, is an open source application that allows programs written in a range of interpreted languages to run on Android. It also provides a high level API that allows these programs to interact with the Android device, making it easy to do stuff like accessing sensor data, sending an SMS, rendering user interfaces and so on.
You can also check PySide for Android, which is actually Python bindings for the Qt 4.
There’s a platform called PyMob where apps can be written purely in Python and the compiler tool-flow (PyMob) converts them in native source codes for various platforms.
python-for-android is an open source build tool to let you package Python code into standalone android APKs. These can be passed around, installed, or uploaded to marketplaces such as the Play Store just like any other Android app. This tool was originally developed for the Kivy cross-platform graphical framework, but now supports multiple bootstraps and can be easily extended to package other types of Python apps for Android.
BeeWare allows you to write your app in Python and release it on multiple platforms. No need to rewrite the app in multiple programming languages. It means no issues with build tools, environments, compatibility, etc.
It’s an open source project with both Python 2 and Python 3 implementations. You can download the source and the Android .apk files directly from github.
One more option seems to be pyqtdeploy which citing the docs is:
a tool that, in conjunction with other tools provided with Qt, enables
the deployment of PyQt4 and PyQt5 applications written with Python
v2.7 or Python v3.3 or later. It supports deployment to desktop
platforms (Linux, Windows and OS X) and to mobile platforms (iOS and
Android).
According to Deploying PyQt5 application to Android via pyqtdeploy and Qt5 it is actively developed, although it is difficult to find examples of working Android apps or tutorial on how to cross-compile all the required libraries to Android. It is an interesting project to keep in mind though!
Take a look at BeeWare. At the moment of answering this question it is still in early development. It’s aim is to be able to create native apps with Python for all supported operating systems, including Android.