Git Product home page Git Product logo

apkwithmake-kotlin's Introduction

Using make to build a simple android app with kotlin

Description

Traditionally, android apps are built with ant, gradle or an IDE. There's a lot of overhead with these methods and some systems (e.g. my Raspberry Pi) don't have such tools easily available.

If you'd like to build android apps from the command line, this simple program will show you how to do it. As a bonus, you can have all the files to build an app in the same directory.

This method works on my Raspberry Pi.

This version uses kotlin instead of java. See my other repository for java: apkwithmake..

Usage

Look at the Makefile and review the variables at the top. You'll need to update some of these for your system and versions.

Try "make unsigned" to start. If that builds fine, then try "make debug" and "make release" to make a debug apk and a release apk, similar to "ant debug" and "ant release".

Kotlin stdlib

Kotlin code depends on having supporting libraries present. The compiler conveniently comes with kotlin-stdlib.jar which contains such libraries.

However, if I run my dx against kotlin-stdlib.jar, dx returns this error:

PARSE ERROR:
unsupported class file version 53.0
...while parsing META-INF/versions/9/module-info.class
1 error; aborting

As a workaround, this example will extract the class files from kotlin-stdlib.jar and remove the offending META-INF files.

If your version of dx works with your version of kotlin-stdlib.jar, you may be able to skip this workaround. See the comment in Makefile where dx is called.

Bash output

guilty@ftl:~/src/android/skel-kotlin$ make
mkdir -p /tmp/androidbuild
cp AndroidManifest.xml /tmp/androidbuild/AndroidManifest.xml
mkdir -p /tmp/androidbuild/res/drawable
mkdir -p /tmp/androidbuild/res/layout
mkdir -p /tmp/androidbuild/res/values
mkdir -p /tmp/androidbuild/src/com/example/skeleton
mkdir -p /tmp/androidbuild/kotlin
cp icon.png /tmp/androidbuild/res/drawable/
cp main.xml /tmp/androidbuild/res/layout/
cp strings.xml /tmp/androidbuild/res/values/
cp *.kt /tmp/androidbuild/src/com/example/skeleton/
/usr/bin/aapt package -f -m -J /tmp/androidbuild/src -M /tmp/androidbuild/AndroidManifest.xml -S /tmp/androidbuild/res -I /usr/lib/android-sdk/platforms/android-19/android.jar
/usr/bin/javac -source 8 -target 8 -d /tmp/androidbuild/obj -classpath /tmp/androidbuild/src -bootclasspath /usr/lib/android-sdk/platforms/android-19/android.jar /tmp/androidbuild/src/com/example/skeleton/*.java
/opt/kotlin/kotlinc/bin/kotlinc  -classpath /usr/lib/android-sdk/platforms/android-19/android.jar:/tmp/androidbuild/obj/com/example/skeleton -d /tmp/androidbuild/obj /tmp/androidbuild/src/com/example/skeleton/*.kt
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
unzip -q /opt/kotlin/kotlinc/lib/kotlin-stdlib.jar -d /tmp/androidbuild/kotlin
rm -rf /tmp/androidbuild/kotlin/META-INF
/usr/lib/android-sdk/build-tools/27.0.1/dx --dex --output=/tmp/androidbuild/classes.dex /tmp/androidbuild/obj /tmp/androidbuild/kotlin
mkdir -p /tmp/androidbuild/bin
/usr/bin/aapt package -f -m -F /tmp/androidbuild/bin/skeleton.unaligned.apk -M /tmp/androidbuild/AndroidManifest.xml -S /tmp/androidbuild/res -I /usr/lib/android-sdk/platforms/android-19/android.jar
cd /tmp/androidbuild ; /usr/bin/aapt add /tmp/androidbuild/bin/skeleton.unaligned.apk classes.dex
 'classes.dex'...
/usr/bin/zipalign -f 4 /tmp/androidbuild/bin/skeleton.unaligned.apk /tmp/androidbuild/bin/skeleton.unsigned.apk
ls -l /tmp/androidbuild/bin/skeleton.unsigned.apk
-rw-r--r-- 1 guilty guilty 618099 Feb 17 16:37 /tmp/androidbuild/bin/skeleton.unsigned.apk

guilty@ftl:~/src/android/skel-kotlin$ make debug
cp /tmp/androidbuild/bin/skeleton.unsigned.apk /tmp/androidbuild/bin/skeleton.tosign.apk
/usr/bin/apksigner sign --ks ~/.android/debug.keystore -ks-pass pass:android /tmp/androidbuild/bin/skeleton.tosign.apk
mv /tmp/androidbuild/bin/skeleton.tosign.apk /tmp/androidbuild/bin/skeleton.debug.apk
ls -l /tmp/androidbuild/bin/skeleton.debug.apk
-rw-r--r-- 1 guilty guilty 620688 Feb 17 16:37 /tmp/androidbuild/bin/skeleton.debug.apk
guilty@ftl:~/src/android/skel-kotlin$

apkwithmake-kotlin's People

Contributors

sanjayrao77 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.