How to run an app when it does not show under Apps? - android

I used ant to build my Eclipse project from the command line in a debug configuration. (Eclipse Luna and Android NDK-R10d is broken, so I can't use Eclipse any longer. Confer, Eclipse/ADT plugin cannot locate symbols for r10d NDK).
I then performed an install using adb:
<Project Directory>$ adb install bin/AndroidPrng-debug.apk
When I rummage for the program on the device in Apps, the program is not offered. When I attempt to search for it by name on the device (AndroidPrng and com.example.prng), I'm provided with useless web search results. When I go to Settings → Apps, the app is shown under the Downloaded tab (it shows the name as com.example.prng). It has the familiar Force Stop and Uninstall.
I have DDMS running and waiting to capture LogCat output from the program. But even though the app is on the device, I cannot figure out how to run it.
How do I run and debug the app when it does not show up under Apps?

Assuming that your app do have an Activity from where you can navigate into other parts of your app.
Try using below command:
$ adb shell am start -n com.example.yourpackagename/.YourMainActivity
or $ adb shell am start -n com.package.yourpackagename/com.example.yourpackagename.YourMainActivity
This am start command, is a command-line interface to the ActivityManager.

Related

React Native app: cannot connect to dev server, but the simulator is running - why?

The image describes my current situation properly. Please have a look at it first.
I am running my app on React Native. I have Android simulator on. I give the command to start the app. The app build finishes, but it says that virtual device not found, and in my simulator, if I open the app manually, it says that it cannot connect to Development server. It shows some issues.
Can anyone help?
Try run react-native run-android to connect your app to the emulator
Check USB Debugging is on(mostly running on virtual devices)
Check how you created project(react-native-cli or Expo) and run relevant app run command
Make sure your development server(node.js) is running when you run app. Sometimes it crashes then you have to again run command to run app
If all the step does not solve your issue try to uninstall app from device and run app again. Since react-native is still developing and its wired sometime these tricks works
I was having the same issue in Ubuntu 16.04. In my case the problem was that node packager wasn't running.
To check is packager is running easily you can open the browser and enter
http://localhost:8081/
You must see "React Native packager is running."
If you dont, then you can start packager from console running
react-native start
If you get an error like
" ERROR watch /your/project/path/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-ru ENOSPC"
Then run first
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Then run react-native start again and press the letter R twice in the emulator to reload.
Looking at the screenshot, seems like you don't have adb installed because there is a clear 'adb: not found error'.
Luckily Android studio ships with adb and is present in platform-tools under your Android SDK. (generally in /home/your-user-name/Android/Sdk/)
You only need to use it. Create a symbolic link in '/usr/bin/' or '/usr/local/bin/' depending how you'd like to use it.
Run the command:
sudo ln -s ~/Android/Sdk/platform-tools/adb /usr/local/bin/
After this run the app.

Android Studio run app/test directly if nothing is changed

If nothing is changed since last compile and run, and then I hit run again (green start button), it complies and then run.
How can I make it run directly without compiling the same thing?
I might be wrong, I don't think but it's possible when you pass by Android Studio, but by using the build apk and install it with Android Debug Bridge (ADB), you should get the desired behaviour.
When the project compiles, AS creates an output apk. Usually, this should be named app-debug.apk and located in build/outputs/apk/ folder:
Your .apk file (signed with either a release or debug key) is in your module build/ directory after you build your application.
cf. Running on emulator
By using adb, you'll be able to install this apk previously generated (and I believe, without compiling again) on the device with the command install:
$ adb install -r path/to/app-debug.apk
Once installed, you should retrive the command to launch your application. A little research bring me to "How to start an Android application from the command line?":
$ adb shell
$ adb am start -n my.package.name/my.package.name.MyActivity
And then, you could combined them on same line to launch the apk just right after its installation. This looks like:
$ adb install -r path/to/app-debug.apk && adb shell am start -n my.package.name/my.package.name.MyActivity
Therefore, you application will run without compiling.
First try right click on the project and then select Run As Android Application. This will change you app default run configuration.
If this does't work then try to change it's run configuration from right click on project in project explorer and select Run as -> Run configurations.
Always run your project if you have opened that projects java class tab in workplace. You cannot run your project directly by clicking Green play button if you opened a XML file of that project. However you can run a project if you have opened manifesto of that project.

How to run and debug a C++ Android program in Eclipse

Thanks to cmake-android-chain, I can build a C++ program successfully. By using adb commands, I can also make the program run in Android devices:
adb push c_plus_plus_program /data/local/tmp/c_plus_plus_program
adb shell chmod -777 /data/local/tmp/c_plus_plus_program
adb shell ./data/local/tmp/c_plus_plus_program
Now I want to debug this program in Eclipse. With cmake, I can create a project for Eclipse, and I have also succeeded in building the project. However, the problem is I do not know how to run the program insider Eclipse, hence debugging the program. Any ideas? Thanks.

Which adb commands does eclipse use to run app?

I'm working on an app that uses device admin. If I run the app on a device using eclipse, then make a minor change to the code, then run the app again, the app runs as you'd expect with the new change.
However, if the second time I run the app I use adb install I get:
Failure [INSTALL_FAILED_ALREADY_EXISTS]
If I try to uninstall then reinstall, the uninstall fails because the app is device admin. This has led me to wonder which adb commands eclipse executes when you select run. I've looked for some sort of "update" command but I couldn't find one. Anyone know?
You can use "adb install -r yourapp.apk" to install your system apk again.
If you want to run through command line, use
"adb shell am start -n acticityname_withpackage"

Testing Android Applications on a Clean Emulator

When I want to test an android application, I create a new AVD, start it in the emulator, wait for the emulator to finish booting, and then use ADB to install the application, and when I'm done delete the AVD. Are there any tools that automate all of those steps? I tried writing my own but I couldn't find a way to tell if the emulator was completely booted, as the Android SDK website says not to use "adb wait-for-device install file.apk".
You're right not to use wait-for-device. It does not wait for the package manager to be available, which is what you need. I'm not sure how eclipse does it but you can poll the emulator until the package manager is available using the command adb shell pm path android. The command should return 'package: something'. Check out this python script that uses the technique: www.netmite.com/android/mydroid/1.6/.../adb_interface.py. It's pretty big but if you search for the command above you'll find the relevant piece of the script.
Why do you want to delete the AVD every time?
If you are deleting it every time because the install command throws an error due to the app already existing on the AVD, you can do this: adb install -r file.apk. The -r part is used for reinstalling the app. Here is the full usage instructions for adb.
Are you deleting it to remove the application you are testing and revert to a 'clean' emulator? If so it's not necessary to delete the AVD every time. You can specify the -wipe-data option when starting the emulator. This effectively resets the AVD to how it was when you created it. Here is the emulator documentation.
Hopefully that helps simplify your script.

Categories

Resources