https://blog.mindorks.com/implementing-merge-adapter-in-android-tutorial
Android and MQTT: A Simple Guide
The Top 20 Android Studio Plugins
maintainable-architecture-lifecycle
android-annotation-processing-tutorial-part-1-a-practical-approach
android-development-the-solid-principles
https://kelvinma.medium.com/exploring-android-processes-bf74ba63552c
dynamic-feature-module-android-ondemand-module-android-app-bundle
modular-and-dynamic-app-delivery-android-app-bundle
Memory Leak Hunt
https://square.github.io/leakcanary/fundamentals-fixing-a-memory-leak/
https://www.intertrust.com/resources/the-practical-guide-to-application-hardening/
CodeProtection whiteEncryption
Android Studio Profile
Room DB upgrade https://infinum.com/handbook/books/android/common-android/room-migrations View at Medium.com https://blog.mindorks.com/room-database-with-kotlin-coroutines-in-android https://www.sqlite.org/datatype3.html https://www.sqlite.org/omitted.html ANR how to check and fix
TraceView and Profiling
Tracview call using code
// start tracing to "/sdcard/calc.trace"
Debug.startMethodTracing("calc");
// ... your code goes here it could be within method or across class of other method
// stop tracing
Debug.stopMethodTracing();
adb pull /sdcard/calc.trace /tmp
Using dmtracedump
dmtracedump
is a tool that gives you an alternate way of generating graphical call-stack diagrams from trace log files. The tool uses the Graphviz Dot utility to create the graphical output, so you need to install Graphviz before running dmtracedump.
The dmtracedump tool generates the call stack data as a tree diagram, with each call represented as a node. It shows call flow (from parent node to child nodes) using arrows. The diagram below shows an example of dmtracedump output.
dmtracedump [-ho] [-s sortable] [-d trace-base-name] [-g outfile] <trace-base-name>
https://developer.android.com/studio/profile/record-traces
https://developer.android.com/studio/profile/android-profiler
https://android-doc.github.io/tools/debugging/debugging-tracing.html https://blog.usejournal.com/how-to-deal-with-anrs-d01a792080c https://developer.android.com/topic/performance/vitals/anr
select bugreport in developer settings first. Take bug report
Also from developer option we can collect the bugreport.
adb bugreport folderPath
adb root
adb shell ls /data/anr
adb pull /data/anr/anr_*
Debugging over wifi in android
- Connect the device via USB and make sure debugging is working.
adb tcpip 4455
//4455 is any not used port- find the IP address with
adb shell netcfg | grep "wlan"
oradb shell ifconfig | grep "addr"
with 6.0 and higher, on windows instead ofgrep
replace withfindstr
in the command adb connect :5555
- Disconnect USB and proceed with wireless debugging.
adb -s :5555 usb
to switch back when done or runadb usb
Git Command
git commit –amend -m “message”
# Alternatively, if there’s work to keep:
git stash
git reset –hard commitID
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts if you’ve modified things which were
# changed since the commit you reset to.
git reset –soft commitID
Linux Find Command
Find log in java files
find . -name “*\.java” | xargs sed -ri ‘:a; s%Log\.[ivdwe].*\);%;%; ta; /Log\.[ivdwe]/ !b; N; ba’
find . -name “*\.java” | xargs grep -l ‘Log\.’ | xargs sed -i ‘s/Log\./;\/\/ Log\./g’
Uncomment logs:
find . -name “*\.java” | xargs grep -l ‘Log\.’ | xargs sed -i ‘s/;\/\/ Log\./Log\./g’
Gradle Command
./gradlew android:assembleDebug –profile
./gradlew android:assembleDebug –dry-run –profile
./gradlew android:assembleDebug –dry-run –profile –configure-on-demand
./gradlew android:assembleDebug –dry-run –profile –configure-on-demand –daemon
./gradlew build –dry-run
gradlew –profile –recompile-scripts –offline –rerun-tasks assembleFlavorDebug
ADB Command
adb shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
adb shell cat /data/local/tmp/lldb-server | run-as your.package.name sh -c ‘cat > /data/data/your.package.name/lldb/bin/lldb-server && chmod 700 /data/data/your.package.name/lldb/bin/lldb-server’
adb shell cat /data/local/tmp/start_lldb_server.sh | run-as your.pacakge.name sh -c ‘cat > /data/data/your.pacakge.name/lldb/bin/start_lldb_server.sh && chmod 700 /data/data/your.pacakge.name/lldb/bin/start_lldb_server.sh’
adb shell am start -n “your.package.name/youtActivityPackageName.yourActivityName” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
adb shell dumpsys package your.package.name | grep -i “version”
adb shell pm list package | grep -i “any String which is in pacakge”
adb shell pm path your.package.name
aapt dump badging inSystemApkPath.apk
aapt dump badging /path/to/apk | grep -c application-debuggable
adb shell dumpsys package my.package | grep versionName
adb shell dumpsys package my.package | grep versionCode
zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk
zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk
keytool -genkey -v -keystore /path/of/your/.android/debug.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias
apksigner sign –ks my-release-key.jks –out my-app-release.apk my-app-unsigned-aligned.apk
apksigner sign –ks /your/path/of/debug.keystore –out /your/path/of/apks/univeral2/universalSign103.apk /your/path/of/apks/univeral2/universal.apk
https://www.jetbrains.com/help/idea/accessing-android-sqllite-databases-from-product.html
adb shell am start -n “your.pacakge.name/.SplashActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
adb install-multiple -r -t -g slice_5.apk slice_0.apk slice_4.apk slice_9.apk slice_7.apk slice_6.apk slice_8.apk slice_3.apk slice_2.apk resources-AMGTest-debug.apk slice_1.apk dependencies.apk TrackPace-AMGTest-debug.apk
adb install-multiple -r -t -g base-arm64_v8a_2.apk base-master_2.apk base-xxhdpi.apk
adb install-multiple -r -t -g slice_5.apk slice_0.apk slice_4.apk slice_9.apk slice_7.apk slice_6.apk slice_8.apk slice_3.apk slice_2.apk slice_1.apk dependencies.apk
adb shell am start -n “your.package.name/.SplashActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
bundletool build-apks –bundle= –output=
mkdir out.apks
java -jar ~/Downloads/bundletool-all-0.3.3.jar build-apks –bundle=./app/build/outputs/bundle/debug/bundle.aab –output=out.apks
mkdir apks
unzip out.apks -d apks
ls -l apks
/***
* to trace back the call of any method in from begining to this calling method in java
*/
public void traceBack(){
try {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StringBuilder from = new StringBuilder();
for (int i = 0; i<stackTrace.length; i++)
from.append("\nclass:")
.append(stackTrace[i].getFileName())
.append(",method:").append(stackTrace[i].getMethodName())
.append(",line:").append(stackTrace[i].getLineNumber());
Log.i("TAG", "from:"+from + ",lineNo:" + Thread.currentThread().getStackTrace()[2].getLineNumber());
} finally {}
}
App life cycle from support lib
Just ensure you pull this dependency in your build.gradle file:
dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:1.1.0"
}
Then in your Application class, use this:
class ArchLifecycleApp : Application(), LifecycleObserver {
override fun onCreate() {
super.onCreate()
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onAppBackgrounded() {
Log.d("MyApp", "App in background")
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onAppForegrounded() {
Log.d("MyApp", "App in foreground")
}
}
In the end, update your AndroidManifest.xml file with:
<application
android:name=".ArchLifecycleApp"
//Your extra code
....>
</application>