MobileUI LogoMobileUI
/

Add MobileUI to an Android app


The MobileUI Framework is a set of Java libraries. Therefore, you can simply use it in your Android app projects like any other Java library.

Gradle dependency

MobileUI comes with an installer, that installs the MobileUI libraries into your Maven local repository. To use them within your Android project, make sure that mavenLocal() is set as a repository location. This can be done in the parent build.gradle as shown below:

build.gradle
allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()    }
}

Then, add the following dependency to your app module's build.gradle file:

build.gradle
dependencies {
    implementation "io.nevernull:mobileui-android:<version>"    ...
}

Note: Replace <version> with 0.5.3

Location of MobileUI Assets

If your are working with a standalone Android project, you can put the MobileUI assets (layout files, CSS files, images) into the folder

<YOUR-APP-MODULE>/src/main/assets

Alternatively, you can specify any other folder to contain the assets. To do this, add an additional sourceSet to your app module's build.gradle file as shown below:

build.gradle
android {
    sourceSets {        main.assets.srcDirs += '../app-common/src/main/assets'    }    ...
}

This is the default approach, if you generate a new MobileUI project with an app-common module containing all assets for Android and iOS.

Init MobileUI in your Application class

In order to use the MobileUI framework, it must be initialized by the application. You can do this by adding a line to your custom Application sub class. It might be necessary to create such a class. An example is shown in the listing below:

Application.java
public class MyApplication extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();
        MobileUIAndroid.init(this);    }
}

If you needed to create the custom Application class, you need to add it to the AndroidManifest.xml as follows:

AndroidManifest.xml
<application 
   android:name=".MyApplication"   android:icon="@drawable/icon" 
   android:label="@string/app_name" 
   >

Apply MobileUI in your Android app

To use MobileUI layouts in your app, please follow the Applying Layouts guide.