Android Studio Keyboard shortcut control - android

Can anyone give me some suggestion or link of all controls of Android Studio keyboard shortcuts?

Move to File -> Settings -> Keymap and change Keymaps settings to eclipse so that you can use the short cut keys like in eclipse.

Preferences > Keymap will show you all the keyboard bindings.
A couple helpful hints to help you find features:
You can search actions by name; on MacOS the keybinding is Command+Shift+A. You can start typing the name of a command and it will show you all matching commands and their key bindings if they have one. That's really convenient for looking up the key shortcut for something if you have a hint of what it's called.
In most dialogs/windows there's a search box, and you can usually just start typing to start a search. It's especially good for preferences, where there are so many options that are hard to find.

I may be late to answer this, but would like to help all others who come up to this page from now.
Here is the list of all the most productive shortcuts that I have been using regularly in my day to day Android development. It saves a lot of time, seriously.
Find only classes - CMD + o
Find files - CMD + Shift+ o
Find everything - Double Shift
Find symbol - CMD + Alt+ o
Find in page - CMD + f
Find usages - fn + Alt+ f7
Generate boilerplate code - CMD + j
Quick fix - Alt + Enter
Code completion - Ctrl + Space
Definition of a class or method - Alt + Space
Navigate to a class or method - CMD + Left Click
Refactor rename - fn + Shift+ f6
Run app - Ctrl + R
Format code - Alt + CMD+ L
Show documentation - fn + f1
Mode code up/down - Shift + CMD+ up/down
Generate Code - CMD + N
Recently opened files - CMD + e
Recently edited files - CMD + Shift+ e
Delete lines at one go - CMD + Delete
Add single line comment - CMD + /
Add block comment - CMD + Alt+ /

On the Mac OS go to Android Studio -> Preferences -> Keymap

to assign a keyboard shortcut, you need to navigate to
file --> setting --> keymap --> search and than right click and add keyboard shortcut --> in first stroke
you can add/change like
ex:
you want to assign Cntl + w than use Cntl with w

Android Studio > Preferences > Keymap > Select Your Option.
Default is: IntelliJ IDEA Classic
After Android Studio updating, you sometimes need to do that. For example, I updated Android Studio 4.2.1 and I did this because it turned automatically default Keymap which is IntelliJ IDEA Classic. I prefer to use MacOS.

Go to Help and select Default Keymap Reference will point you to one of these default keyboard shortcuts for Android Studio. It has all the keyboard shortcuts you can do in Android Studio. It's says for it's IntelliJIDEA but Android Studio is based off IntelliJIDEA, so all the keyboard shortcuts listed there apply in Android Studio.
Windows and Linux
Mac

Here is the official list of the shortcuts of Android Studio for Windows, Linux and Mac:
https://developer.android.com/studio/intro/keyboard-shortcuts.html#configure_custom_keymaps

if you have a favourite plugin that doesn't have a shortcut, just navigate to
Settings > KeyMap > Double click Plugins > Select desired plugin > Add
Keyboard Shortcut :: Then press down the hot keys you want to assign for the
plugin and click OK.
PS. be careful not to override any important AS shortcut.

Related

Empty spaces in-between lines added after updating Android Studio to 2022.1.1 Patch 1

Empty spaces are added to the editor after updating to the last version.
look at lines 114-115
how to disable it?
Apple M1 chip Android studio 2022.1.1 Patch 1
This is a known issue, please check related SO post.
You can try to use a newer version of Android Studio (from 2022.2), or the workaround mentioned in the above post:
Disable Code author option in Settings (MacOS: ⌘ + , Win/Linux: Ctrl + Alt +S) > Editor > Inlay Hints > Code Vision.

Failed to update Android SDK Package List - Unity 2019.2.10f1

When I try to export the game build for the Android platform, I started getting this error:
Within the Project Settings - Minimum API Level and Target API Level not get loaded anyhow!
While I have used all default Unity provided settings to export Android build.
Here is the image to illustrate this:
Now what to do to solve this error?
I have already read all the threads related to same problem but overall I can't able to find the solution that actually worked for me.
Project Settings > Player > Target API Level: Change "Automatic" to "Android 11" (or else)
Play once and Stop.
Change target api level to Automatic.
I don't know if the problem is the same, but this is how I handle it every time.
Edit: Now I just do this; I open the Other Settings Tab in Player Settings. Error appears in console. I Play and Stop it once and the error goes away (No need to change API Levels)
I just got the same error on MacOS using both Unity 2019.4.18.f1/2019.2.21.f1 and after a lot of messing around I think I might have figured some of it out.
At times ( don't know why ) Unity ( or something else ) starts resetting the JAVA_HOME environment variable to string empty when you start Unity. So even if you set JAVA_HOME via console or .bashrc/.zshrc depending on MacOS version it still doesn't work.
Some posts mentioned adding "/" to the end of the external tools SDK path. I think that just forces Unity to set the path again which makes it work for a while. But for me the the error just came back the second day.
I permanently fixed it adding an editor script to the Editor folder that changes the JAVA_HOME environment variable every time Unity starts/loads.
Here's the method for MacOS, just paste it in a C# script in the editor folder.
[InitializeOnLoadMethod]
static void SetJavaHome()
{
//Debug.Log(EditorApplication.applicationPath);
Debug.Log("JAVA_HOME in editor was: " + Environment.GetEnvironmentVariable("JAVA_HOME"));
string newJDKPath = EditorApplication.applicationPath.Replace("Unity.app", "PlaybackEngines/AndroidPlayer/OpenJDK");
if (Environment.GetEnvironmentVariable("JAVA_HOME") != newJDKPath)
{
Environment.SetEnvironmentVariable("JAVA_HOME", newJDKPath);
}
Debug.Log("JAVA_HOME in editor set to: " + Environment.GetEnvironmentVariable("JAVA_HOME"));
}
This worked for me :- Edit>Prefrences>In JDK Click copy path> then Uncheck JDK and Paste the copied path again in that and after OpenJDK add \
like this : Before : C:\Program Files\Unity\Hub\Editor\2020.1.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
After : C:\Program Files\Unity\Hub\Editor\2020.1.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\
If that doesn't works than uncheck JDK,SDK,NDK,Gradle and Stop Gradle (all five boxes) than close unity. Open Again and Check all five boxes again.
I don't know why, but on mac os unity may use latest version of java if you have one.
If you have installed a few versions of java, you can just remove all except java v1.8.
You can check which version of java you have by typing in terminal /usr/libexec/java_home -V.
You should have 2 or more versions.
If you installed them with brew, you can just use brew to uninstall extra java packages.
Also you can update JAVA_HOME system variable by type
echo export "JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" >> ~/.zshrc.
This solution worked for me.

Shortcut to create new line in Android Studio editor

What is the shortcut to create a new line in Android Studio editor (like ctrl+enter in Visual Studio Code)?
I believe its Shift + Enter
If you want to change it ::
Go to File > Settings > Select Keymap > Select Editor Options > Start
a New Line
Shift + Enter
List of android studio keyboard shortcuts:
Android keyboard shortcuts

Android NDK app not able to hit any breakpoint

I am using https://www.youtube.com/watch?v=kjsC-lKUgM8 tutorial to try to debug a simple NDK app. I have done everything as it is in the video except:
I am on OS X 10.9.3 instead of Windows.
I don't use android:debuggable=true(cause eclipse considers it as error) in AndroidManifest.xml instead I have set the NDK path from Preferences->Android->NDK and in Project Properties -> C/C++ Build unchecked Use default build command and set there ndk-build NDK_DEBUG=1 APP_OPTIM=debug.
I don't use x86 emulator but Samsung Duos S device with Android 4.0.4
But the breakpoiin that is used in the video in not being hit in my case. I am trying to debug a simple NDK test project already the 4th day. Have investigated lots of material:
Android Native Development Kit Cookbook
Bunch of forums and tutorials
Videos
But can not hit a single damn breakpoint. Please help if you could do this ever.
The following is an excerpt from an tutorial I wrote for our internal Android development team. The bulk of which was derived from this blog: http://mhandroid.wordpress.com/
Important notes:
I use a Linux (Ubuntu 12.04) environment for my Android work.
I used the ADT Bundle for Linux, Build: v22.2.1-833290 (Eclipse IDE + Extras)
These steps are for debugging from a Java Activity into a JNI shared object.
I created test projects for this tutorial which won't be posted here, though references to those projects are present in the instructions that follow. You'll need an existing Android Application Project as well as a JNI shared object that is being called by your Java code.
Project Setup
Enable Debugging.
Open AndroidManifest.xml, select the Application tab, and set Debuggable=true. This will make the application debuggable even when it's running on a device that's running in user mode.
4. Build the Native Sources. From the Terminal, enter the project directory and enter:
ndk-build -B
You should see the following output:
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : DebuggingTestJNI <= com_sample_test_DebuggingTestActivity.cpp
StaticLibrary : libstdc++.a
SharedLibrary : libDebuggingTestJNI.so
Install : libDebuggingTestJNI.so => libs/armeabi/libDebuggingTestJNI.so
Clean the Project. In the Eclipse menu strip, select Project→Clean. It is good to perform this step anytime you change/build your native sources. This step ensures that Eclipse will rebuild your .apk.
Native Debug Setup
Create Java Debug Configuration. We need to create a debug configuration for stepping into Java source code.
In the Eclipse toolbar, you'll see a green bug. Click the little arrow next to the bug and select "Debug Configurations…".
Double-click "Android Application" in the tree structure on the left. This will create a template for a new Android Application Debug Configuration.
In the "Name:" field, name it "DebuggingTest Java Debug" to make sure you know this Configuration applies specifically to the DebuggingTest project, and targets your Java source.
Under "Project:", click the "Browse…" button and select DebuggingTest.
Click "Apply" to save your changes.
Click "Close".
In the Eclipse toolbar, click the little arrow next to the bug and select "Organize Favorites…".
Click "Add…"
Select "DebuggingTest Java Debug" and click "OK".
Your new debug configuration has now been created and added to your favorites. You can access your favorites by clicking the little arrow next to the bug in the toolbar. "DebuggingTest Java Debug" should be at the top of the list.
Run ndk-gdb.
In the Eclipse toolbar, click the little arrow next to the bug and select "DebuggingTest Java Debug". This will deploy and install the DebuggingTest.apk to your connected Android device and start the debugger.
Navigate to the DebuggingTest project directory in your Terminal and type the following:
ndk-gdb
If the command succeeds, you should see the following:
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-elf-linux".
(no debugging symbols found)
…
If you forgot to start debugging the application before this step, you get the following:
ERROR: Could not extract PID of application on device/emulator.
Are you sure the application is already started?
Consider using --start or --launch= if not.
If your Android.mk file is malformed or contains $(info) blocks, you get the following:
cp: target ./obj/local/armeabi/gdb.setup' is not a directory /home/Dev/NDK/ndk-gdb: 639: cannot create start DebuggingTest/jni/Android.mk end DebuggingTest/jni/Android.mk ./obj/local/armeabi/gdb.setup: Directory nonexistent /home/Dev/NDK/ndk-gdb: 640: cannot create start DebuggingTest/jni/Android.mk end DebuggingTest/jni/Android.mk ./obj/local/armeabi/gdb.setup: Directory nonexistent start: invalid option: -x Try start --help' for more information.
If ndk-gdb is already running, you get the following:
ERROR: Another debug session running, Use --force to kill it.
Resolve your ERRORs before continuing. ndk-gdb MUST run successfully.
Running ndk-gdb does not only ensure us that we are doing everything right so far, but also creates app_process, gdb.setup and libc.so files in the obj/local/armeabi/ sub-directory of our project. Those files will be needed in later steps.
Stop Debugging.
In your Terminal, type CTRL+Z to stop ndk-gdb.
In Eclipse, select Run → Terminate.
4. Create C/C++ Debug Configuration. We need to create a debug configuration for stepping into C/C++ source code.
In Eclipse, click the little arrow next to the bug and select "Debug Configurations…".
Double-click "C/C++ Application" in the tree structure on the left. This will create a template for a new C/C++ Application Debug Configuration.
In the "Name:" field, name it "DebuggingTest C and CPP Debug" to make sure you know this Configuration applies specifically to the DebuggingTest project, and targets your C/C++ source.
In the "Main" tab:
Click "Browse…" on the "C/C++ Application:" field.
Navigate to "/home/Test/testing/DebuggingTest/obj/local/armeabi/app_process" and click "OK".
Click "Browse…" on the "Project:" field.
Select "DebuggingTest" and click "OK".
Check the "Disable auto build" box.
At the bottom of the form, you'll see "Using GDB (DSF) … - Select other…". Press the "Select other…" button.
In the pop-up, check the "Use configuration specific settings" box.
Select "Standard Create Process Launcher" in the list and press "OK".
In the "Debugger" tab:
Click the combo-box on the "Debugger:" field and select "gdbserver".
Uncheck the "Stop on startup at:" box.
In the "Main" sub-tab:
Click "Browse…" on the "GDB debugger:" field.
Navigate to "/home/Dev/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb" and click "OK". This debugger is distributed with the Android NDK.
In the "GDB command file:" field, type "/home/Test/testing/DebuggingTest/obj/local/armeabi/gdb2.setup". The gdb2.setup file does not exist yet, but we'll create it shortly.
Check the "Use full file path to set breakpoints" box.
In the "Connection" sub-tab:
Set "Type:" to TCP
Set "Port number:" to 5039
Click "Apply" to save your changes.
Click "Close"
In the Eclipse toolbar, click the little arrow next to the bug and select "Organize Favorites…".
Click "Add…"
Select "DebuggingTest C and CPP Debug" and click "OK".
Your new debug configuration has now been created and added to your favorites. You can access your favorites by clicking the little arrow next to the bug in the toolbar. "DebuggingTest C and CPP Debug" should be at the top of the list.
Create gdb2.setup. Eclipse doesn't like the "target remote :5039" line in gdb setup file because it wants to enter this command internally (that is why you configured port 5039 in the previous step). Because the gdb.setup file is recreated by the NDK scripts, you have to copy it to the gdb2.setup and point Eclipse to the gdb2.setup file (which we did in the previous step).
In your File Explorer, navigate to "/home/Test/testing/DebuggingTest/obj/local/armeabi/".
Copy the "gdb.setup" file and then paste it into the same folder. The result should be a file named "gdb (copy).setup".
Rename "gdb (copy).setup" to "gdb2.setup".
Open gdb2.setup by double-clicking the file.
Replace "set solib-search-path ./obj/local/armeabi" with "set solib-search-path /home/Test/testing/DebuggingTest/obj/local/armeabi".
Replace "file ./obj/local/armeabi/app_process" with "file /home/Test/testing/DebuggingTest/obj/local/armeabi/app_process".
Remove the line that reads "target remote :5039".
Save and Close the file.
5. Create ndk-gdb-eclipse. One last Eclipse housekeeping item. Eclipse will run the gdb binary itself, so we have to remove the execution of gdb from ndk-gdb. We'll save the original content by doing another Copy-Paste-Rename.
In your File Explorer, navigate to "/home/Dev/NDK".
Copy the "ndk-gdb" file and then paste it into the same folder. The result should be a file named "ndk-gdb (copy)".
Rename "ndk-gdb (copy)" to "ndk-gdb-eclipse".
Open ndk-gdb-eclipse by doing a right-click → Open With Other Application …
Select Text Editor from the list of applications
In the file, locate the line that reads "$GDBCLIENT -x native_path $GDBSETUP" (probably at the very bottom) and comment it out by prefixing it with a "#" character.
Save and Close the file.
When Debugging native sources within the Eclipse IDE, we'll use ndk-gdb-eclipse instead of ndk-gdb.
Debugging/Stepping into Code
Step Into the Java Code!
Put a breakpoint in the DebuggingTestActivity.java file at line 20 (System.out.println("hello world!")).
Insert a breakpoint in your main Activity BEFORE any calls into native code are made. onCreate() is generally the best place for this.
Start the DebuggingTest application in Debug mode by clicking on the little arrow next to the bug and selecting "DebuggingTest Java Debug".
You'll see a pop-up on the screen labeled "Confirm Perspective Switch". Press "Yes" if you'd like it to switch to your Debug Perspective. I would recommend doing so.
At this point, you should have hit the breakpoint you set.
Warning: The breakpoint we just hit sits inside of the onCreate function. This function will be called AFTER all static loadLibrary calls have been made. Notice that outside of the onCreate function there is a System.loadLibrary("DebuggingTestJNI") inside of a static block. This loadLibrary call will execute before we enter our onCreate function, ensuring that our native symbols are loaded by the time we hit our initial breakpoint. It is imperative that we are stopped at a breakpoint before proceeding!
Step Into the C/C++ Code!
In your Terminal, navigate to the DebuggingTest directory and type the following command:
ndk-gdb-eclipse ← Remember that we created this file back in step 6
If successful, the command should complete without any response.
Go back to Eclipse and run your C/C++ debugger by clicking the little arrow next to the bug and selecting "DebuggingTest C and CPP Debug"
Note: When I do this, I see dozens of errors in my Eclipse console, but things still seem to be working…
Switch back to your Java Perspective.
Click the double arrows at the top right of right of your Eclipse window and select Java.
Open DebuggingTest/jni/com_sample_test_DebuggingTestActivity.cpp
Set a breakpoint in the first JNI function that will be called by your main Activity.
Click Run → Resume (F8)
You'll get the Perspective Switch message again, so feel free to switch back to the Debug Perspective.
You should have just hit the breakpoint we just set in the native code!
Congratulations!!!
At this point you should be able to take what you've learned and adapt it to existing projects you may have.

Autocompletion not showing in Android Studio with dual screens

I just switched from Eclipse to Android Studio (IntelliJ).
I can't figure out how the autocompletion works! I tried Control + Space, Control + Shift + Space but i have no relevant suggestion. Not in the Java files, not in the layout files.
Is there another shortcut? Do I need to enable some option beforehand?
Preferences > Keymap > Code > Completion > Basic/SmartType:
It was actually a display problem. I'm using two screens, and the suggestions only appear when the IDE is on the main one.
The (imperfect) solution is to define the display where I'm using the IDE as the main one.
Just remove all the folder "AndroidStudioPreview";
On Windows:
Go to your User Folder - on Windows 7/8 this would be:
[SYSDRIVE]:\Users\[your username] (ex. C:\Users\JohnDoe\)
In this folder there should be a folder called .AndroidStudioPreview
On Mac OS X
Remove these files:
~/Library/Application Support/AndroidStudioPreview
~/Library/Caches/AndroidStudioPreview
~/Library/Logs/AndroidStudioPreview
~/Library/Preferences/AndroidStudioPreview
You can get your Autocompletion suggestions back in Android Studio by doing: File>Invalidate Coches/Restart...>Invalidate and Restart

Categories

Resources