Site icon GEEKrar

How to Use Meteor to Build Android Apps

If you’re thinking of building your own android app, Meteor might be the help you need. It’s a full-stack Javascript platform that was first introduced in 2011 for rapid prototyping and cross-platform production. It works alongside MongoDB, Node.js, and Javascript and utilizes the Distributed Data Protocol and a publish-subscribe pattern to instantly alter data according to clients’ requests without having to write any synchronization code.

In this article, we’ll take you through the basics of Meteor and how you can use it to build an android app of your own.

Why use Meteor?

Firstly, it helps its users to develop in one language such as JavaScript. Instead of requiring clients to render an HTML file, Meteor can bypass this and send data directly to the server. It also provides full stack relativity, which allows the UI to reflect actual states with minimal development effort. Here we break down the basic steps of building an Android app. Keep in mind that Meteor utilizes the Cordova library to publish apps.

How to use Meteor

1st Step

Installing Meteor will require two different ways depending on your operating system. On Linux and OSX, use the cURL command to specify the server location and use the resource provided by Meteor to set up the program.

curl https://install.meteor.com/ | sh

For Windows, the node package manager is used to install meteor.

npm install -g meteor

Now that we have successfully installed Meteor, it’s time to create a project. Simply input the meteor create myapp and the cd myapp commands.

meteor add-platform android

A checklist of other things you need will then be displayed. These might include Java JDK, Android SDK, Android target, Gradle, among others. No other versions aside from Java 8 will work, so make sure you set it as your default. Install the command-line only sdkmanager tool, then connect all of these to Meteor by editing the ~/.bashrc.

export ANDROID_SDK_ROOT=/yourAndroidStudioPath/Android

export PATH=${PATH}:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

export JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre

export PATH=$PATH:/opt/gradle/gradle-6.1.1/bin

export ANDROID_HOME=/home/ubuntu/tools/android

export PATH=$PATH:$ANDROID_HOME/bin

export PATH=/home/ubuntu/tools:/home/ubuntu/tools/bin:$PATH

Source ~/.bashrc as well.

sdkmanager –list

sdkmanager “platform-tools” “platforms;android-28

sudo apt install gradle

2nd Step

We can now move on to building an app.

meteor build ~/appdir –server=192.168.x.x:3000

Don’t be worried if you see error notices like “No installed build tools found. Install the Android build tools version 19.1.0 or higher” or “missing java.se.ee” – simply re-export to make sure you’re using the right path into the terminal and keep trying to solve all errors.

The next step is to run the following command to set the encryption key and sign the app.

keytool -genkey -alias your-app-name -keyalg RSA -keysize 2048 -validity

10000

Then go to where the apk is located and run jarsigner, making sure to note where your android sdk tools are.

cd mydir/android/project/app/build/outputs/apk/release/

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 app-release-unsigned.apk your-app-name

Locate the zipalign tool and run the a similar command to

/home/ubuntu/tools/android/build-tools/27.0.1/zipalign 4 app-release-unsigned.apk testapp.apk

Congratulations! Your testapp.apk is working signed, and you can choose to put it on your phone or upload it to the app store.

3rd Step

You’ll also need to take data from your database and render it on the front end. This is done through MongoDB, which is a document-oriented NoSQL database that perfectly integrates with Meteor. In the example below, we’ve created a Mongo collection named ‘newarrivals’ and exported it to be utilized in other files.

import { Mongo } from ‘meteor/mongo’;

export const LinksCollection = new Mongo.Collection(‘newarrivals’);

Once you’ve created the collection, you can begin inserting data into the back end. Take note of how we have used LinksCollection which was exported from the links.js file.

import { Meteor } from ‘meteor/meteor’;

import { LinksCollection } from ‘/imports/api/links’;

function insertLink({ title, url }) {

LinksCollection.insert({title, url});

}

Meteor.startup(() => {

insertLink({

 title: ‘Cyber Hacks’,

url:

‘https://www.geekrar.com/how-can-you-protect-your-company-from-the-latest-cyber-hacks/’

});

insertLink({

title: ‘Android Apps’,

url:

‘https://www.geekrar.com/7-best-educational-android-apps/’

});

You can now finally fetch the data from the database into the front end. The useTracker can be used to handle all aspects of the components. We also use several li tags with the help of the map function.

Conclusion

If this is your first time building an APK from scratch, there might be a bit of a learning curve. Thankfully, Meteor development is much smoother than native and can make development easier for creating responsive and reactive mobile applications on newer devices. This is especially useful now that foldable phone shipments are expected to reach 41.5 million in 2026, according to statistics from the International Data Corporation.

Exit mobile version