Friday, September 20, 2019

Update date time using batch file

For dual OS, sometimes windows show date incorrect. You need to go setting and force windows to synchronize its date time.
The easy way and fast is using batch files. Using text editor, create batch files for example datesync.bat in your desktop. Write or copy/paste this code:

Echo off
Echo Starting Windows Time Service
net start w32time


Echo Syncronizing Date Time
w32tm /resync
pause

Everytime your date show incorrect, run this script as administrator. It will start windows time service (should not be disable on services.msc) and syncronize date time from internet.

Android Studio 3.5: Clone android project into new android project with diferent name

Requirement and test on Android Studio 3.5

Make sure your old project working properly with your existing android studio library.

1. Copy project directory and rename folder for new project name e.g. Bramara
2. Open your existing new project using Android Studio 3.5. After opening project complete,  Navigate to 1: Project -> Project. You may seen your project only has two directory pointing to new project folder and old project folder. Close your project.
3. Edit appl.iml on directory new project -> app -> appl.iml using text editor. Replace all old project name into new Project Name.
4. Reopen your exising new project. Navigate to 1: Project -> Project. You may seen your project only has one directory.
5. Navigate to 1: Project -> Packages. right click on your component -> Refactor -> Rename.
6. A Warning message will pop up. Make sure all change will apply to new project folder! After that choose Rename packages e.g. com.dedetok.bramara.
7. Navigate to 1: Project -> Android. Open app -> manifests -> AndroidManifest.xml. Fix Application Activity to new pakage name. Change your Application Name to a new one.
8. Open Gradle Scripts -> build.gradle (Module: app), change your applicationId to new project, e.g com.dedetok.bramara and sync project.
9. Clean and rebuild your new project.
10. Your new project to edited/change.

Note: if adb run showing activity not found, edit your Run/Debug Configuration. Module should point to module application e.g. app

Wednesday, September 4, 2019

Android Studio 3.5.0 and Migrate to AndroidX

System requirement:

Android Studio requirement 3.5 or above

At the end of "Project -> Gradle Scripts -> gradle.properties(Project Properties)" add these lines:

    android.useAndroidX=true
    android.enableJetifier=true

At the end of "Project -> Gradle Scripts -> build.gradle(Project:)" add these lines:

...
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'

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

    repositories {
        jcenter()
        google()
    }
}

Change "Project -> Gradle Scripts -> build.gradle(Module:)" these lines:

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' -> androidx.test.espresso:espresso-core:3.2.0

implementation 'com.android.support:appcompat-v7:28.0.0' -> androidx.appcompat:appcompat:1.1.0

implementation 'com.android.support.constraint:constraint-layout:1.1.3' -> androidx.constraintlayout:constraintlayout:1.1.3

androidTestImplementation 'com.android.support.test:runner:1.0.2' -> androidx.test:runner:1.2.0

implementation 'com.google.android.gms:play-services-ads:17.2.1' -> com.google.android.gms:play-services-ads:18.2.0

For Example:

...
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'
  
In Java code, change import android.support.v7.app.AppCompatActivity; to import androidx.appcompat.app.AppCompatActivity;

In activity xml, change android.support.v7.widget.Toolbar to androidx.appcompat.widget.Toolbar

References: