android
browsing the device
First list your devices with
``` title="example output with List of devices attached 192.168.1.151:5555 device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64 device:emulator64_x86_64_arm64 transport_id:10246 adb-5b611dcd-9yupU7._adb-tls-connect._tcp device product:Nord_EEA model:AC2003 device:Nord transport_id:6943
My Nord One is now not connected by usb but through wifi, so it also has an ethernet link (.\_tcp)
If it is connected by usb, you will get something like
``` title="nord one via usb"
# adb devices -l
5b611dcd device usb:3-1 product:Nord_EEA model:AC2003 device:Nord transport_id:1
If you only have 1 usb device, you could use -d, if only 1 ethernet device -e Otherwise just use the transport id:
emulators
After a gap of two years without programming android i came back to an emulator that is still unworkable slow. So
emulator
Do NOT used the built in emulator of android studio. It is SLOW and BUGGY.
Instead try to make one in a VM or go to this site for a docker solution
docker run -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_12.0
Note that the -p commands are vital. If you forget them the docker ps will look like it has the ports open.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
208e82a4e0d0 budtmo/docker-android:emulator_11.0 "/home/androidusr/do…" 4 minutes ago Up 4 minutes 4723/tcp, 5554-5555/tcp, 5900/tcp, 9000/tcp, 0.0.0.0:6080->6080/tcp, :::6080->6080/tcp android-container
However that only shows the ports are open on the inside of the container. When you try to connect with adb it will say "Connection refused"
When you start it up with the -p it will look like this :
208e82a4e0d0 budtmo/docker-android:emulator_11.0 "/home/androidusr/do…" 4 minutes ago Up 4 minutes 4723/tcp, 0.0.0.0:5554-5555->5554-5555/tcp, :::5554-5555->5554-5555/tcp, 5900/tcp, 9000/tcp, 0.0.0.0:6080->6080/tcp, :::6080->6080/tcp android-container
Now open http://localhost:6080 and view a working emulator. This even seems to be able to open your real device !?
You should now also be able to view it in the android studio device manager.
troubleshooting
gradlew gives lint errors
The problem here was that android studio compiled the code just fine, but the gradle wrapper gave errors.
``` title="./gradlew ... For more details, see https://developer.android.com/studio/write/lint#snapshot
Lint found 2 errors, 12 warnings. First failure:
/home/kees/AndroidStudioProjects/Roadmap/app/src/main/java/org/klopt/roadmap/ Explicitly handle a potential SecurityException [MissingPermission] mMap.setMyLocationEnabled(true); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
The problem here is that gradlew performs a lint check on top of building. If you run lint in android studio yourself, you will indeed get the same errors.
This particular error could be fixed by adding checks around mMap.setMyLocationEnabled(true);
``` title="check permissions"
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
} else {
Toast.makeText(MapsActivity.this, "You have to accept to enjoy all app's services!", Toast.LENGTH_LONG).show();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
}
}
By the way...