Damilola Olowookere
Damilola Olowookere

Reputation: 2383

How to develop for Android on a 32 bit Linux

The title of the question is the best I could give it, and that is exactly what I want to do: to develop Android apps on a 32 bit Linux (specifically, 32 bit Ubuntu, running moderately latest kernel 4.4.0-66-generic; 3G RAM).

What I have learnt/tried so far:

  1. Android SDK stopped supporting dev on 32 bit Linux OS since >23 upwards
  2. For Android Studio, I can't get around appcompat so that I can build for lower version of android (e.g. version 19) because in the face of no option/instruction/clear directive, I changed com.android.support:appcompat-v7:25 to com.android.support:appcompat-v7:19 so I wasn't surprised when I got the error that appcomat could not resolve com.android.support:appcompat-v7:19
  3. At that stage, a notice popped up in Android Studio that I do not need appcompat for sdk version > 19 and build tools < 21 (or something like that) and then I removed com.android.support:appcompat-v7:19 then the next error is failed to resolve com.android.support:design:19

  4. I tried googling for any instruction/process guide specifically directed at developing Android apps on 32 bit Linux but find none!

  5. I tried Cordova but stuck at gradle build (maybe it is still because of the same issue above: android-sdk not supporting dev on 32 bit Linux) since Cordova still depends on android-sdk

From my google-wandering I stumbled on Cordova, and I love it (maybe because it is CLI-based and that I can see/control everything, it even has a --verbose option that shows all that is happening under the hood) but after reading several other articles I pieced together to get it to build on my 32 bit Linux, I still got stuck at the build stage because when the build process reaches the gradle stage, it stubbornly insists on using build-tools 25.0.2, and with all the articles I pieced together about how to set the build-tool version, I just couldn't get any way to persuade gradle to use the build-tools 19 that I already have fully installed (using the Android SDK Manager). To make gradle work for me, I have tried setting <preference name="android-targetSdkVersion" value="19"/> in config.xml and even set cdvBuildToolsVersion=19 in ~/project_folder/platforms/android/gradle.properties yet with all these efforts in Cordova I get rewarded with:

Execution failed for task ':preBuild'. failed to find Build Tools revision 19.0.0

BUILD FAILED

I just want to setup a simple, decent, working Android development environment on a 32 bit Ubuntu OS!

Directions/guides/hints/help please!

btw, please don't suggest moving to a 64 bit Linux...at least not for now

Upvotes: 3

Views: 11675

Answers (2)

Gavin Simpson
Gavin Simpson

Reputation: 2832

Following this fantastic tutorial for 64 bit, I managed to get it working 100% on 32bit Ubuntu Linux, running on an old Celeron PC. I created the hellow orld app, and ran it on my Samsung A5. The entire process took about 3 to 4 hours as I had to figure some things out for 32 bit.

The version numbers are dated, but important, as the current versions do not support 64 bit.

  1. sudo apt-get install gradle
  2. install oracle 8

    sudo add-apt-repository ppa:webupd8team/java sudo apt update; sudo apt install oracle-java8-installer javac -version (to confirm version) sudo apt install oracle-java8-set-default

    (set this java version as default)

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-i386 export PATH=${JAVA_HOME}/bin:$PATH

  3. Install adndroid SDK

  curl -O https://dl.google.com/android/android-sdk_r21.0.1-linux.tgz
  tar zxf android-sdk_r21.0.1-linux.tgz
  curl -O https://dl.google.com/android/repository/build-tools_r21-linux.zip
  unzip build-tools_r21-linux.zip
  mkdir android-sdk-linux/build-tools
  mv android-5.0 android-sdk-linux/build-tools/21.0.1
  curl -O https://dl.google.com/android/repository/android-16_r05.zip
  unzip android-16_r05.zip
  mv android-4.1.2 android-sdk-linux/platforms/android-16
  curl -O https://dl.google.com/android/repository/platform-tools_r21-linux.zip
  unzip platform-tools_r21-linux.zip -d android-sdk-linux/
  1. Write "Hello World" app folders
cd ~
mkdir android
cd android
mkdir helloworld
cd helloworld
  1. create "AndroidManifest.xml" as follows :
<?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="net.gavin.hello"
              versionCode="1"
              versionName="0.1">
      <uses-sdk android:minSdkVersion="16"/>
      <application android:label="Hello">
          <activity android:name=".MainActivity">
              <intent-filter>
                  <action android:name="android.intent.action.MAIN"/>
                  <category android:name="android.intent.category.LAUNCHER"/>
              </intent-filter>
          </activity>
      </application>
  </manifest>
  1. create folders "res/layout/"
cd ~/android/helloworld
      mkdir res
      cd res
      mkdir layout
      cd layout
  1. create "activity_main.xml" as follows
<?xml version="1.0" encoding="utf-8"?>        <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center"
          android:orientation="vertical">
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/my_text"/>         </LinearLayout>
  1. java/net/gavin/hello/
cd ~ 
mkdir java
cd java
mkdir net
cd net
mkdir gavin
cd gavin
mkdir hello

9.create " MainActivity.java" as follows

package net.gavin.hello;
        import android.app.Activity;
        import android.os.Bundle;
        import android.widget.TextView;
        public class MainActivity extends Activity
        {
            @Override
            protected void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                TextView text = (TextView)findViewById(R.id.my_text);
                text.setText("Hello, world!");
            }
        }
  1. Create build enviroment

    cd ~ SDK="${HOME}/android-sdk-linux" BUILD_TOOLS="${SDK}/build-tools/21.0.1" PLATFORM="${SDK}/platforms/android-16" mkdir -p build/gen build/obj build/apk

  2. Create R.java (build/gen/net/gavin/hello/R.java)

"${BUILD_TOOLS}/aapt" package -f -m -J build/gen/ -S res -M AndroidManifest.xml -I "${PLATFORM}/android.jar"

  1. Compile it

    javac -source 1.7 -target 1.7 -bootclasspath "${JAVA_HOME}/jre/lib/rt.jar" \ -classpath "${PLATFORM}/android.jar" -d build/obj \ build/gen/net/gavin/hello/R.java java/net/gavin/hello/MainActivity.java

  2. Convert to Dalvik code

    "${BUILD_TOOLS}/dx" --dex --output=build/apk/classes.dex build/obj/

  3. Package contents together

    "${BUILD_TOOLS}/aapt" package -f -M AndroidManifest.xml -S res/ \ -I "${PLATFORM}/android.jar" \ -F build/Hello.unsigned.apk build/apk/

  4. Align to 4 byte boundry "${BUILD_TOOLS}/zipalign" -f 4 build/Hello.unsigned.apk build/Hello.aligned.apk

  5. Create key store and key keytool -genkeypair -keystore keystore.jks -alias androidkey \ -validity 10000 -keyalg RSA -keysize 2048 \ -storepass android -keypass android
  6. Install ket signer (apksigner) sudo apt-get install apksigner
  7. Sign app with key "apksigner" sign --ks keystore.jks \ --ks-key-alias androidkey --ks-pass pass:android \ --key-pass pass:android --out build/Hello.apk \ build/Hello.aligned.apk
  8. Install to device "${SDK}/platform-tools/adb" install -r build/Hello.apk
  9. Run on device "${SDK}/platform-tools/adb" shell am start -n net.gavin.hello/.MainActivity
  10. Celebrate famously, cos that was hectic.

NB : 19 and 20 assume you have set your phone to developer mode, and it's connected to your PC via USB. In this case I simply ftp'd it to my phone, and installed from there. No problems.

Upvotes: 6

Damilola Olowookere
Damilola Olowookere

Reputation: 2383

I finally came up with a rather easy way out: run Windows in a Virtual Machine!

While Google dropped support for 32 bit Linux, it still supports 32 bit Windows.

So all I did was to install 32 bit Windows on my 32 bit Linux Machine and then run Android Studio on top of that - installed all pre-requisites like Android SDK...etc. From this point onward, I simply shifted focus to looking for support/guides in Windows-Oriented guides. Easy, Cool, Simple!

Upvotes: 0

Related Questions