11 Jul 2020

Create Android Apps without Android Studio - IV

Android Apps without Android Studio - 4

Understanding the files

First we will note the files and directories we don’t have to deal with.

Do not delete these files. We will need them when we will build our app.

- .gitignore         : Contains list of files that 
                        will not be uploaded to Git
- .gradle             : For gradle's build settings
- gradle-wrapper.jar  : Binary file
- gradlew             : Contain environment variables
- gradlew.bat         : Contain environment variables

So, we are left with our code files that we will be modifying.

Now we will add this code to our settings.gradle file.

settings.gradle
include ':app'
rootProject.name = "Fromis"

Now we will create a gradle.properties file. Android X is the enhanced version of android libraries. We will be using this for ease of developing.

gradle.properties
# When configured, Gradle will run in incubating parallel mode.
# org.gradle.parallel=true
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official

And here is the last file in the main directory.

This is a build file for the global environment of the project.

There will be another file we will be creating in the app folder after this file …

Yeah Android has these stupid structures. Even Google is trying to get rid of this Android mess.

build.gradle
# Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        # NOTE: Do not place your application dependencies here; they belong
        # in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Now create an ‘app’ folder in the main directory.

Inside the app folder, create a ‘build.gradle’ file.

Do not get confuse this 'build.gradle' file with the same named file in main directory. This file is specific for the app folder.

app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.example.fromis"
        minSdkVersion 15
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

In the ‘app’ folder, create a folder named src

Inside the ‘src’ folder, create a file named AndroidManifest.xml

and enter the below code in the file.

app/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fromis">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <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>

In the next post, we will create our main code files where we will be writing the logic of our app.



Share this

Tag :