Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 20

4
votes
answers
15 views
+10

Can you deploy to a device via Gradle from the command line

What the question says really - can you issue any commands directly to gradlew via the command line to build, package and deploy to a device?

沙发
+20
task appStart(type: Exec, dependsOn: 'installDebug') {
    commandLine android.adbExe, 'shell', 'am', 'start', '-n', 'com.example/.MyActivity'
}

最佳解決方案 - Orgatres 2016年7月20日16:15

板凳
+10

I wrote this task to be able to install and also open the application on the device. Since I had multiple buildTypes and flavors with different application ids, it was not feasible to hard code the package name. So I wrote it like this instead:

android.applicationVariants.all { variant ->
    task "open${variant.name.capitalize()}" {
        dependsOn "install${variant.name.capitalize()}"

        doLast {
            exec {
                commandLine "adb shell monkey -p ${variant.applicationId} -c android.intent.category.LAUNCHER 1".split(" ")
            }
        }
    }
}

This would give you open{variant} for every install{variant} task you already have.

地板
+10

Build -> uninstall old verion -> install new version -> run application.

echo "Build application" && ./gradlew clean build && 
echo "Uninstall application" && adb uninstall [application package] && 
echo "Install application" && adb -d install app/build/outputs/apk/<build type>/[apk name].apk echo "Run application" && 
adb shell am start -n [application package]/.[application name]

Or if you want install and run application in debug type.

./gradlew installDebug && adb shell am start -n [application package]/.[application name]

謝謝。@ alexander-polomodov - Goffity 18年5月14日11:15

107
votes
answers
17 views
+10

Android Studio - No JVM Installation found

I'm having issues trying to boot-up Android Studio

When I try to launch it after installation I'm getting this error:

No JVM Installation found. Please install a 64 bit JDK.


My current system specification:

Operating System: Windows 8.0 64 bit version
JDK installed: JDK 1.8.0


What I have tried:

I have tried what was reported in the error, and also in most of the solutions to set the JDK_HOME variable in environment variables to my JDK path (64 bit version) i.e. C:Program FilesJavajdk1.8.0_05

*I also have tried rebooting system, just in case to test if the environment variable is not working without a restart


I have seen these solutions and tried but none of them works, so don't mark it as a duplicate of any of these:
Android Studio installation on Windows 7 fails, no JDK found
With android studio no jvm found, JAVA_HOME has been set
Android Studio start fails on Windows 8 64bit
Android Studio does not launch after installation


Here is the cmd output for java version:

enter image description here

沙发
+480

I reproduced your issue on my Windows 8.1 system :

  1. Installed 64-bit JDK 1.8.0_11.
  2. Installed latest Android Studio Bundle.
  3. Went to Control Panel -> System -> Advanced system settings -> Environment Variables...
  4. Added JDK_HOME pointing to my 64-bit JDK.
  5. Launched studio64.exe

I got the same message you did. Thinking that it might be the environment variable, I did the following :

  1. Went to Control Panel -> System -> Advanced system settings -> Environment Variables...
  2. Changed the name of JDK_HOME to JAVA_HOME.
  3. Launched studio64.exe

It came up successfully !

板凳
+300

1 .Download 64 bit version of JDK from here

enter image description here

  1. As shown in next picture, go to Control Panel -> System and Security -> Advanced system settings -> Environment Variables -> New (System variables)

  2. Then add variable name: JAVA_HOME and variable value: C:Program FilesJavajdk1.8.0_25

Please note that jdk1.8.0_25 may be vary depending on JDK version. enter image description here

  1. Click OK button on the rest of the windows left.
地板
+110

1-Right click on Android Studio and click on properties.

2-Replace studio64.exe in link by studio.exe.

謝謝伙計,它有效 - Sumit Pathak於2016年4月8日9:08

將studio64.exe替換為C:Program FilesAndroidAndroid Studio?中的studio.exe,並在桌面上創建了一個新的studio.exe快捷方式。一切都很好。謝謝。 - Mian Asbat Ahmad 2016年5月17日13:32

4楼
+70

Ok, was having this issue as well and this is what fixed it for me. For the record I'm using Windows 8.1 and Java JDK 1.8.31, all 64-bit.

The problem is with the space between "Program" and "Files" in the path set in JAVA_HOME. I've had this problem before but didn't really realize until I was checking the instructions here for setting JAVA HOME, then it all made sense.

In a nutshell, change the JAVA_HOME path from:

C:Program FilesJavajdk1.8.0_31

to

C:Progra~1Javajdk1.8.0_31

Make sure to set the correct JDK version number for your installation. Removing the space from the path fixed everything on my system.

As noted on the page linked above,

use C:Progra~1 for C:Program Files

and C:Progra~2 for C:Program Files(x86)

depending on where you have the JDK installed on your system.

Note: Just to be clear, before making this change my system correctly echoed the value of JAVA_HOME to be C:Program FilesJavajdk1.8.0_31 in the command window, leading me to believe all was well. However, attempting to run %JAVA_HOME%injavac reported that the path could not be found. After removing the space from the JAVA_HOME path the same command runs perfectly.

我在Windows 10上,這個技巧使我的一天。 - NonStatic 2015年2月11日2:08

在Windows 10中,這解決了我的問題,即設置無法正常工作,因為它無法檢測JDK的安裝位置。像這樣的愚蠢廢話就是我討厭Java的原因。 - 約翰遜2015年8月24日19:12

5楼
+30

Uninstall Java 8 and clean your JDK_HOME and your JAVA_HOME enviromental paths. Then install 64bit JAVA 6 or 7 JDK of your preference.

如果我降級JAVA版本,我知道我可以使它工作..但我為什麼要這樣做?這就是問題.. - Syed Qarib 2014年7月29日13:49

正如我試圖建議的那樣,您的JAVA環境路徑可能會因以前的安裝而變髒/欺騙並使Android Studio感到困惑。Intellij Idea幾乎兼容JAVA 8,但你不能利用任何JAVA 8功能,因為Android還不支持它。只需仔細檢查就可以清理它並安裝JAVA 7,就可以了。 - 馬丁回复2014年7月30日4:24

因為你不能在Android中使用Java 8。 - 一個人2014年8月1日23:49

偉大的sio olution ... Java 8與Android Studio不兼容... - Babul Patel 2014年11月12日5:58

6楼
+20

Make sure you set the path in the SYSTEM VARIABLES not in the USER VARIABLES also.....name the variable name as JAVA_HOME and the address as C:Program FilesJavajdk1.8.0_25 be sure that you didn't place any semicolon.

您的樣本路徑幫助了我...非常感謝:) - shihabudheen 2014年12月27日9:52

7楼
+10

According to Oracle's installation notes, you should download/install JDK for the correct system. For your convenience, I have linked to it from the sentence above. If you still encounter problems, leave a comment. I have written some quick code that will tell you if your JVM is 64 or 32-bit, below. I'd suggest you run this class and leave a comment as to its output:

public class CheckMemoryMode {
    public static void main(String[] args) {
        System.err.println(System.getProperty("sun.arch.data.model"));
    }
}

我已經安裝了相同的JDK .. JDK運行良好..因為我沒有問題在eclipse上運行程序.. - Syed Qarib 2014年7月26日在23:52

請編譯/運行我剛剛添加的代碼並讓我知道它的內容。 - hd1 2014年7月27日4:46

它輸出64 .. - Syed Qarib 2014年7月29日13:48

通常對於所有想法產品,bin目錄中都有一個'bat'啟動器。它明確指出JDK_HOME和JAVA_HOME都被接受了。嘗試啟動它,看看之後會發生什麼。至少如果有問題,你會在控制台中看到它。然後你可以查看bat文件的來源。它完全是自我描述。 - simar 2014年7月30日6:18

8楼
+10

Just make sure that the installed version of both, Android Studio and JDK, are of either 32-bit or 64-bit. If JDK is of 32-bit and Android Studio of 64-bit or vice-verse, then it won't work though you set up JAVA_HOME.

9楼
+10

The solution is given in the error itself, Goto My computer(Right click)-->properties-->Advanced system settings-->Environment variables-->Create new variable.

Give the following details to it:

Variable name : JAVA_HOME.

Variable value : (your path to java jdk installation folder).

To find the path for java installation, go to program files in your window installation drive (normally C drive). Find folder named JAVA, in that navigate to JDK folder.

Copy the link address from the top, and paste it in the Variable value .

Now Press Ok and once environment variable gets created restart the android studio.

Hope it helps.

10楼
+10

My fix was to remove the double quotes that I had enclosed the JAVA_HOME path in.

Instead of declaring JAVA_HOME as "CProgram Files..."

I removed the " and declared JAVA_HOME as CProgram Files...

I am on Win 7, x64

11楼
+10

I also faced the same issue. The solution which helped me was I downloaded and installed 64 bit JDK from this link and set the "java_home" variable to the new JDK installed path like C:Program FilesJavajdk1.7.0_45. Hope this helps.

12楼
+10

Had the same problem after upgrading my machine from 7 to 10 had to reinstall the JDK all overgain and took me only a few seconds. Here are the steps I followed.

Go to this link http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Agree to oracle contact agreement.Then pick your windows version in my case is 64 bit after that its ..Next..Next,,once compete you can relaunch your Android studio without any problem. Hope this helps

13楼
0
  • For me this turns out to be Environment Variables not being inherited.
  • Quick answer: reboot, than click on studio.bat, not studio.exe or studio64.exe

================ Details =================

  • "Right Click"-"Run as Administrator" works for me if: ** JDK_HOME or JAVA_HOME was set. (PATH didn't need to be changed for me) ** I run studio.bat, not studio.exe ** Note: By Default I am an administrator on a Microsoft Account (That Microsoft part may be affecting things), and I seldom reboot. I'm running Win8.1 64bit. I installed both JDKv1.8.0.0_25 32bit and 64 bit, and had JRE 32bit and 64 bit already installed (used by other software).

  • I found there was a difference in clicking on studio.bat, studio.exe, and running studio.bat from a command prompt. There is also a difference if I rebooted or not.

  • The difference: The System Environment Variables aren't all there depending on how I start the program.

  • To test:

  • In start menu drag a copy of "command prompt" to your desktop, then change properties so "Start In" is location of studio.bat

  • copy studio.bat to studio_debug.bat (one we can mess with)
  • drag a shortcut of studio_debug.bat to desktop for convenience.
  • edit studio_debug.bat (right click --> edit)

== Change:

@echo off

== to

@echo on         
echo Set===================
set
echo ======================
pause
  • This may also help in debugging studio.bat:

== change:

"%JAVA_EXE%" %ALL_JVM_ARGS% -cp "%CLASS_PATH%" %MAIN_CLASS_NAME% %*

== to

echo =================
echo Starting: "%JAVA_EXE%" %ALL_JVM_ARGS% -cp "%CLASS_PATH%" %MAIN_CLASS_NAME% %*
pause
"%JAVA_EXE%" %ALL_JVM_ARGS% -cp "%CLASS_PATH%" %MAIN_CLASS_NAME% %*
echo =================
  • Now when you run studio.bat from command prompt versus double clicking you may see difference in environment variables including JAVA_HOME and PATH. If you do you have same problem as me.

  • The problem seems to depend on:

    1. did you reboot since changing environment variables?
    2. didn't seem to matter if I was local or microsoft account
    3. may depend whether you are an administrator or other account type
    4. whether you start using studio.bat, studio.exe, or studio64.exe
  • .

  • FYI: The actual successful startup command executed by studio.bat on my system was as follows (includes studio64.exe):

    "C:Program FilesJavajdk1.8.0_25injava.exe" "-Xms128m" "-Xmx750m" "-XX:MaxPermSize=350m" "-XX:ReservedCodeCacheSize=96m" "-ea" "-Dsun.io.useCanonCaches=false" "-Djava.net.preferIPv4Stack=true" "-Djsse.enableSNIExtension=false" "-XX:+UseCodeCacheFlushing" "-XX:+UseConcMarkSweepGC" "-XX:SoftRefLRUPolicyMSPerMB=50" "-XX:+HeapDumpOnOutOfMemoryError" "-Didea.platform.prefix=AndroidStudio" "-Didea.paths.selector=AndroidStudioBeta" -Djb.vmOptionsFile="C:android-studioinstudio64.exe.vmoptions" "-Xbootclasspath/a:C:android-studioin../lib/boot.jar" -Didea.paths.selector=AndroidStudioBeta -Didea.platform.prefix=AndroidStudio -cp "C:android-studioin..libootstrap.jar;C:android-studioin..libextensions.jar;C:android-studioin..libutil.jar;C:android-studioin..libjdom.jar;C:android-studioin..liblog4j.jar;C:android-studioin..lib rove4j.jar;C:android-studioin..libjna.jar;C:Program FilesJavajdk1.8.0_25lib ools.jar" com.intellij.idea.Main

  • Hope that helps someone else.

14楼
0

Android Studio Works Perfectly fine with Java 1.8 or Java 8. I was also having invalid JVM error. The reason was including ";" (semicolon) at the end of JAVA_HOME path value. The correct format for path value is:

C:Program FilesJavajdk1.8.0_xx (Replace xx with your current version)

Do not include ; (semicolon) at the end of JAVA_HOME value

15楼
0

For crying out loud this is so VERY EASY TO Fix!!

  1. Go to : "Control PanelAll Control Panel ItemsSystem" once there click on "Advanced system settings" on the left hand side

  2. The window that pops shows a box that says says Environment Variables! Click it.

  3. Click "add new" to add new variable.

  4. Type JAVA_HOME in the first box and in the second box the address to, IE / in my case C:Program FilesJavajdk1.8.0_25 save it. exit everything. THATS IT!!

Enjoy Android Studio! Obviously for the above to work you have to install java first or how else can you use it or point to it on your pc and all that. The above instructions are amazingly mislead and complicated. For the record I am on widows 8.1, YES it works on latest windows and is ridiculously simple to fix.

-OSG

只是一個建議,但不要與人交談,我認為你會更好。包括我自己在內的許多人完全按照建議做了 - 添加系統env var JAVA_HOME指向JDK文件夾位置,通過回顯%JAVA_HOME%(設置為C:Program FilesJavajdk1.8.0_31)來檢查它是否正確cmd提示符似乎都已正確設置,但Android Studio無法啟動,顯示“無效的JVM安裝”消息。有了這麼多的活動,對於每個人來說,顯然不是“非常簡單易於修復”。 - 蘭德爾2015年1月21日19:56

@randall:這個問題的大部分答案都和這個問題一樣,但令人遺憾的是人們在回答之前甚至沒有閱讀整個問題,在問題本身我提到過我試過這個問題。 - Syed Qarib 2015年3月1日5:21

16楼
0

In my case

In Control Panel -> System -> Advanced system settings -> Environment Variables there is no JDK_HOME OR JAVA_HOME

SO

I added an entry named: JDK_HOME pointing to: C:Program FilesJavajdk1.8.0_25 (you have to point this to your JDK instalation path)

And all seems to work fine now

17楼
0

You must just install jdk1.8.0 and then right click on my computer icon and then select properties,then in left panel, select advanced system settings, then in dialog bog select Environment Variables, then in that's dialog box,in section user variables create new variable that's name must be JAVA_HOME and path is C:Program FilesJavajdk1.8.0(in my pc) then sytem variable section, select PATH variable and append it's end this path C:Program FilesJavajdk1.8.0in and then select ok for all dialog box and after this steps run Android studio. And for test, run cmd in windows and run this command java -version if returned a java version and ... it is installed correctly.

Note: I get answer in windows 8.1 64 bit.

18楼
0

This is tested on my Windows 7 64Bit machine.

Quite strange... I had the same issue - WHILE IntelliJ Idea (including the Android Plug-in) was working perfectly.

However, here is what I did to get Android Studio 1.0 working (no step missing -> maybe it will help programming beginners).

Just set up a new environment variable by...

  1. pressing Windows-Key and typing env... you'll see "Edit the system environment variables". Click!
  2. Now click "Environment Variables..."
  3. Under System variables (NOT "User variables") add a new entry named JAVA_HOME and set the value to your Java folder (like C:Program FilesJavajdk1.8.0_25)
  4. apply and you are good to go.

PS: I don't know why some people writing about nuclear science when they want to explain how to set the Java path..

19楼
0

if your "enviornment variables" set well, than try to update Start > All Programs > Android Studio > Android Studio

do right click, click Properties and set android studio sdk path

in

shortcut > Target

20楼
0

If you are using windows 7, make sure you install jdk-xxxx-windows-x64.exe. http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html I had previously installed 32 bit instead of 64 bit version hence it was installed in program files x(86) folder. But if you install 64 bit sdk setup, its installed in program files folder. Then set the JAVA_HOME='C:Program FilesJavajdk1.8.0_65' It should work fine.

21楼
0

My variables pointed to other system variables so JDK_HOME was

%programfiles%Javajdk1.8.0_45

and i had to explicitly change it to

C:Program FilesJavajdk1.8.0_45

Similar for JAVA_HOME

22楼
0

My JAVA_HOME was pointing to c:/jre directly. So I changed it to C:/java/jre because it was confused to pick up which one to use, so I changed it to the specific one and it works for me. Note: It is better to have only one JRE install on your machine

23楼
0

I solved the problem in my case by deleting file

C:Usersusername.AndroidStudioXstudio64.exe.vmoptions

( x denotes the version of your android studio so it can be different ) , because I created it before to customize VM options. It's that simple

24楼
0

Add the your installation path and java path to the default system path by separating the ;

Right click on My Computer-->Properties-->Advances System Setting-->Advanced -->Environment Variables-->Under System Variables category find the "Path"-->add the android installation path and java path by separating with ;...

Believe it works

25楼
0

If it does not work after setting paths in environment variables correctly,
Reinstall Android Studio and it worked for me.

按預期工作。但是即使文件在“src / test / resources /”下無法使用,測試也會通過,例如:“rules.xml”,但在這種情況下,InputStream結果為null。 - anand krish 2017年10月23日10:19

kotlin:val myFile = ClassLoader.getSystemResource(“myFile.txt”)。readText() - jj。2月10日20:08

像魅力一樣工作! - Amit Bhandari 2月20日12:55

26楼
-10

I think Android does not support Java 8. Officially android need java 6 as mentioned at the below:

https://developer.android.com/sdk/installing/installing-adt.html

Here I'm providing you a good link, hope those will clear this question :

Is it possible to use Java 8 for Android development?

不.Android支持JDK 7.您應該檢查Android Studio而不是ADT。developer.android.com/sdk/installing/studio.html - Dalinaum 2014年10月17日6:10

我做了一些非常相似的事情(Kotlin):1。創建文件夾和文件:root / app / src / test / resources / test.json 2.讀取這樣的數據:val jsonFile = ClassLoader.getSystemResource(“test.json”) .readText() - jj。2月10日20:10

27楼
-10

Here comes the solution.

Just start ANDROID STUDIO as administrator if you are using a non administrator windows profile!

If your environment variables are correct that will do the trick. Enjoy!

這與問題無關。試試自己 - user586399 2014年12月7日15:31

它對我有用!我遇到了同樣的問題--Kuldeep 2015年4月6日9:25

很棒的答案(經過45分鐘的搜索

太好了!我在這裡看到相同的資源加載問題。AS 2.3.2,Gradle 3.3。由於構建/資源/測試未包含在交互式類路徑中,因此測試可以從命令行進行,但不能通過AS進行。 - Mark McKenna於2017年5月17日14:18

28楼
-10

Control Panel -> System -> Advanced system settings -> Environment Variables

I changed JAVA_HOME to JAVA and again changed JAVA to JAVA_HOME.

and Its working fine.

而不是使用this.getClass()。getResourceAsStream(test.json)?我在那裡添加了文件,在項目的根目錄中,它仍然找不到文件。 - 弗蘭克2015年4月7日15:01

這可以用於使用新的File()或類似方法加載文件,但它不能直接使用上面描述的類路徑加載方法。它也有點棘手,因為每個新的運行配置需要設置工作目錄,默認情況下AS和Gradle命令行喜歡使用不同的工作目錄...這樣的痛苦 - Mark McKenna 17年5月17日在14:28

0
votes
answers
11 views
+10

Count lines of code in all java classes in Android Studio

Is there any way I can view the total lines of code in each java class in my project?

Looking for something like this for Android Studio.

278
votes
answers
12 views
+10

Android Studio recognizes physical Device as Null?

I've been developing an Android Application for Android (SDK min version 14) and I have testing it normally with tablets such as Samsung Galaxy 2 and Nexus 7. However when I tried to run the application (by clicking run in AndroidStudio), AS does not recognise the tablet information, which is shown in the picture below.

Device is Null

The interesting thing is that as shown in the picture above, AS is also detecting the device sdk as API 1 when it's Android version is 4.2.2 The tablet is already set to accept "USB debugging" in the developer options, I'have tried rebooting the tablet, and restarting AS, but still I get the same problem(everything is fine with nexus 7 and Samsung Galaxy 2).

The tablet/device I'm working on is a "VeryKool" T742

Environment information:
 OS: ubuntu
 AndroidStudio version: 0.8.6

 Tablet Android version:4.2.2
 Tablet Kernel version: 3.4.5
 App min SDK: 14
up vote 153 down vote accepted favorite
沙发
+1530
+50

Ok So I finally found the problem, apparently on this device you have to set to connect as camera(even after usb debugging is already enabled)

enter image description here

Also this link describes the setting up process

也在我的工作!不知道是什麼原因! - bmnepali 2016年2月24日8:05

你如何訪問你展示的屏幕? - arekolek 18年2月2日11:57

+560

I've seen this error a few times when adb hasn't been connected with correct permissions.

On the terminal try

~/Android/Sdk/platform-tools> ./adb devices    

if it returns

<deviceIdentifier> no permissions

then you need to restart adb with correct perms

~/Android/Sdk/platform-tools$> ./adb kill-server
~/Android/Sdk/platform-tools$> sudo ./adb devices

if that worked then you'll get

List of devices attached
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
<deviceIdentifier>  device

No more Sdk version resolution issues in Android Studio after that.

通過這樣做,我得到了我的設備名稱(沒有空)只是一秒鐘。它再次顯示為空 - Shruti於2017年4月15日在7:00

這是最正確的答案,因為即使在連接類型更改後,Google Pixel設備也為空。 - Kostya Bakay 18年7月25日8:25

真棒!謝謝。 - 基里爾Starostin 18年11月19日4:50

+200

Just run this command after you connect your device to your Ubuntu system:

adb devices

This works for me.

Note: Make sure you have selected file transfer option in your phone.

stackoverflow.com/a/34598874/9022007嘗試這個,如果adb設備不適合你 - Rashil Shah 8月8日'18在12:17

它對我也有用。謝謝。 - Pinkesh Darji 18年9月27日7:27

它為我工作。1)adb設備2)設置 - >連接設備 - > USB - >更改為'傳輸文件' - amitabha2715 18年6月6日8:21

+140

On Ubuntu, with my Pixel XL on 8.0, I had to do this while plugged into computer:

Settings -> Connected Devices -> USB --> Change to 'Transferring Files'

設置什麼? - arekolek 18年2月2日11:53

電話的設置 - RESTfulGeoffrey 18年2月3日在13:22

沒有為Pixel工作。 - Malwinder Singh 18年7月19日9:41

經過一段時間的連接,我發現我的Pixel正在切換為null。我一直在重啟設備,但同樣的事情會發生。這有時會修復它但只是暫時的,奇怪的... - hmac 18年8月7日在13:29

它為我工作。1)adb設備2)設置 - >連接設備 - > USB - >更改為'傳輸文件' - amitabha2715 18年6月6日8:20

+110

Have the same problem with my Nexus 5/5X/Pixel 2 XL on Ubuntu 18.04.

A permanent solution is to add a udev rule so that you can always access the device.

  • Find your device with the command lsusb. This outputs e.g. for my Pixel 2 XL this:

    Bus 001 Device 003: ID 18d1:4ee7 Google Inc.
    
    # This means: BUS=001, DEVICE=003, VENDOR=18d1, PRODUCT=4ee7
    
  • Now check the permissions. Replace 001 and 003 with your parameters:

    ls -l /dev/bus/usb/001/008
    
    # Output: crw-rw-r-T 1 root root 189, 8 Nov 10 18:34 /dev/bus/usb/001/003
    # Unless you are root, you are missing the permissions to access the device
    
  • To fix this, create a udev rule file with sudo nano /etc/udev/rules.d/51-android.rules with the following content:

    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee7", MODE="0660", 
    GROUP="plugdev", SYMLINK+="android%n"
    
    # You need to replace "18d1" and "4ee7" with your output of `lsusb` above
    
  • Unplug and plug you device back in. It should now always be recognized. If not, restart the adb server a last time with adb kill-server.

Source: http://www.janosgyerik.com/adding-udev-rules-for-usb-debugging-android-devices/

這應該是公認的答案。 - Minoru 3月31日22:10

+60

Ran into the same problem while using Android Studio on Ubuntu. Apparently for me the fix was to set the USB connection mode for the device as MTP.

+50

First check adb version:If it gives Output like

Android Debug Bridge version 1.0.32

Then just restart the daemon.

sudo adb kill-server
sudo adb start-server

else install adb first and restart the daemon Worked for me, in ubuntu 16.04.3

+40

Disabling and re-enabling debugging while the device was connected did the trick for me.

在Ubuntu上沒有為Pixel工作。 - Malwinder Singh 18年7月19日9:43

+40

I had the same problem.

I solved it by opening my Android device Settings, then selecting "Turn off" then "Turn on" for USB Debugging.

在Ubuntu上沒有為Pixel工作。 - Malwinder Singh 18年7月19日9:42

+40

Recently, I was facing the same issue for Vivo and MI phones. I have tried everything described in this thread. I tried connecting as MTP, PTP; But nothing worked.

After many retries I found a solution for my case and may be it can help others too.

  1. Open terminal window in Android Studio
  2. Kill ADB server using following command: adb kill-server
  3. Restart ADB server using following command: adb start-server

It solved my issue.

謝謝救了我的一天..它總是顯示24213213 [null]但是在你操控之後它現在顯示三星Galaxy ... - waza123 2月9日13:57

高興!有效。 - Dhaval 2月9日14:05

+10

On ubuntu installing adb worked for me, I think there was some problem with default android studio one .

In terminal use command

sudo apt install adb 
0

Sometimes in Linux (Centos 6 in my case) the reason can be that you didn't started Android Studio as the root user. please restart android studio as the root user and try it!

這是一個糟糕的主意。永遠不要以root身份啟動userland應用程序 - agilob 2016年4月19日19:15

0

For ubuntu machine select the transfer option and device will detected in android studio as well as for debugging. Generally device is at charging state for windows but for ubuntu this is how it works.

Also many a times device is not detected , do the same thing again.

0

Needed MTP mode, but it does not come up under the USB side. In the storage setting on the menu bar item you get to set the PC connection type as ... MTP.

0

check processes running, i had several adb processes running and i think this was screwing things up for me. Kill them all then restart Studio. HTC Sync Manager, GenyMotion etc and possibly when you have multiple Android Studio windows open can result in multiple conflicting adb processes.

0

On Ubuntu especially or any other platform. Please and Please Check your adb version. I can't stress this enough. ensure it is updated or the lastest version especially if the above answers doesn't work and this link also does not work.

After I updated my platform-tools folder located at

PATH_TO/Android/Sdk/platform-tools

which also contains the adb it worked. I ran
adb devices

first it would show unauthorized then

you unplug and re-plug the android device. Then your phone would ask for permission before the system would read your device.

0

I had the same problem. I resolved this by doing

  1. Android -> SDk -> platform tool

2.Open terminal for(ubuntu user) or open cmd(window user)

3.type command "sudo adb kill-server"

4.Go to android studio,then reconnect the device.

-10

Go to terminal in android studio and run "adb devices". It will show the connected devices. Then Run the app and the device should show up.

0
votes
answers
23 views
+10

如何在Android Studio 3.0.1中更改新項目的默認文件結構?

2

我一直在嘗試安裝android studio。所有在線教程都遵循一個非常簡單的過程,只需按照提示安裝和製作一個新項目即可。但是,每當我創建一個新項目時,我的默認文件結構都是不同的。我目前正在使用Android Studio 3.0.1。 如何在Android Studio 3.0.1中更改新項目的默認文件結構?

這就是我想要創建的每當我做一個新的項目。 This is what I want to create whenever I make a new project.

這就是我實際得到的。

This is what I actually get.

特別是某些文件夾丟失,如manifest文件夾,res文件夾,每當我創建一個新項目。

每當我做一個新項目時,我怎樣才能達到理想的結構?

我確定它在技術上並不重要,但我希望能夠密切關注教程,使其更易於學習。我一直在這樣一個令人尷尬的大量時間,包括幾個重新安裝。這發生在我的兩臺機器上,一臺是Windows電腦和一臺Mac電腦。

我試過改變緊湊的空中間包。 這是之前, Before 和之後。 After

謝謝!

+0

您沒有爲項目選擇正確的文件夾,或者您打開了一箇舊項目,所以仍然存在編譯錯誤。 – Ibrahim

+0

這是一個新項目。新項目完成後會立即發生此問題。我的問題是由我的Android Studio中的新項目自動創建的文件夾和文件不正確。另外我不擔心編譯。 – SYSTEM

+0

從齒輪的圖標菜單發佈屏幕截圖。 – Enzokie

沙发
0
0

Image

在圖像去設置圖標,然後選擇Compact Empty Middle Packages

+0

感謝您的回覆。這是默認啓用的,並且在關閉或打開時不做任何更改! – SYSTEM

+0

事實上,這是正確的,假設你能夠成功。謝謝! – SYSTEM

13
votes
answers
14 views
+10

Zooming editor window android studio [duplicate]

This question already has an answer here:

This may seem like a silly question but does anyone know how to zoom in/out of the editor window in android studio? I have actually researched it before people give me minus marks. Ctrl+ and Ctrl- seem to fold and unfold methods, there is no zoom control in the view drop-down and all the googleing ive done has referred my to zoom the control feature of a WebView. Am i missing something?

沙发
+80

There is a alternative way to do zoom of my code, using View --> Enter presentation Mode

enter image description here

板凳
+50

On a 2016 Macbook air without an external mouse, do the accepted answer, and pinch on the trackpad to shrink the text, reverse pinch to enlarge.

地板
0

For MacBook Users:

To change font size:

Select **Android Studio** menu (which is present next to Apple icon)-->Preferences--->Editor-->Font-->Size(give size)-->ok

To zoom in and out in Editor:

Select **Android Studio** menu -->Editor-->General-->change font size (zoom) with command and mouse wheel-->ok
0
votes
answers
16 views
+10

如何從編輯文本值的標籤活動的片段Android Studio中3.0.1

-5

代碼:如何從編輯文本值的標籤活動的片段Android Studio中3.0.1

public class CustomerDetails extends Fragment { 
    EditText CustomerCode,FullName,AddressLine1,AddressLine2,MobileNo,EmailId,CustomerType; 
    Button Submit; 
    IonExchangeDataBasehelper ionexchangedatabase; 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
           Bundle savedInstanceState) { 
      // Inflate the layout for this fragment 
    //super.onCreate(savedInstanceState); 
      // View v =inflater.inflate(R.layout.fragment_customer_details,container,false); 
      View v =getActivity().getLayoutInflater().inflate(R.layout.fragment_customer_details,null); 
      CustomerCode=(EditText)v.findViewById(R.id.CustomerCode); 
      FullName=(EditText)v.findViewById(R.id.FullName); 
      AddressLine1=(EditText)v.findViewById(R.id.AddressLine1); 
      AddressLine2=(EditText)v.findViewById(R.id.AddressLine2); 
      MobileNo=(EditText)v.findViewById(R.id.MobileNo); 
      EmailId=(EditText)v.findViewById(R.id.EmailId); 
      CustomerType=(EditText)v.findViewById(R.id.CustomerType); 
      Submit=(Button)v.findViewById(R.id.Submit); 

      Submit.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        String abc = CustomerCode.getText().toString(); 
        Toast.makeText(getActivity(),"hhh :" ,Toast.LENGTH_SHORT).show(); 
        // database(); 
       } 
      }); 

      return v; 

     } 
+1

什麼是錯誤?活動中是edittext嗎? –

+0

你的意思是說,如何從EditText檢索值? –

+0

沒有它的片段,但即時通訊無法獲取edittext的值 –

沙发
0
0

清理你的代碼;嘗試並說,如果你仍然有錯誤

public class CustomerDetails extends Fragment { 
       EditText customerCode,fullName,addressLine1,addressLine2,mobileNo,emailId,customerType; 
       Button submit; 
       IonExchangeDataBasehelper ionexchangedatabase; 

        @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     v = inflater.inflate(R.layout.fragment_customer_details, container, 
     false); 
     // get the reference of views 
         customerCode=(EditText)v.findViewById(R.id.CustomerCode); 
         fullName=(EditText)v.findViewById(R.id.FullName); 
         addressLine1=(EditText)v.findViewById(R.id.AddressLine1); 
         addressLine2=(EditText)v.findViewById(R.id.AddressLine2); 
         mobileNo=(EditText)v.findViewById(R.id.MobileNo); 
         emailId=(EditText)v.findViewById(R.id.EmailId); 
         customerType=(EditText)v.findViewById(R.id.CustomerType); 
         submit=(Button)v.findViewById(R.id.Submit); 

         submit.setOnClickListener(new View.OnClickListener() { 
          @Override 
          public void onClick(View view) { 
           String abc = customerCode.getText().toString(); 
           Toast.makeText(getActivity(), abc ,Toast.LENGTH_SHORT).show(); 
           // database(); 
          } 
         }); 

         return v; 

        } 
358
votes
answers
23 views
+10

DexException: Cannot merge new index 65536 into a non-jumbo instruction

For some unknown reason my app suddenly won't build from Android Studio.

I'm keep getting

> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /home/martynas/android-sdk/build-tools/19.1.0/dx --dex --num-threads=4 --output
...
...
...
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Cannot merge new index 65536 into a non-jumbo instruction!

While the same application is built successfully from command line. I've checked method references count and it's way below the dreaded 64k.

I'm using AS 0.8.11 now.

up vote 53 down vote accepted favorite
沙发
+530
+50

Try to add this line on your project.properties

dex.force.jumbo=true

Which increment the limit for strings in a dex files. And your project will probably compile.

Note : Also with jumbo set, the is another limit of 64K only for methods in an single dex. If you get this limit in the future , you will need to remove some dependencies.

Update - Google Play Services 6.5 (12-08-14)

With version 6.5 Google finally unbundled the Google Play Services. So from now on it'll be possible to selectively compile the APIs into your executable.

Example :

compile 'com.google.android.gms:play-services-maps:6.5.+'
compile 'com.google.android.gms:play-services-ads:6.5.+'

For all the other individual Google Play Services APIs check this page on d.android.com.

Update (21-04-2015) : https://developer.android.com/tools/building/multidex.html

+2400

Set the jumboMode property in build.gradle:

android {
    ...
    dexOptions {
        jumboMode true
    }

}

I also found this useful: Showing dex method count by package.

This works for me. Note that the build.gradle to be changed should be the module that throws com.android.dex.DexException. – Francis Bacon Jul 16 '18 at 11:45

+530

This works for me. I was getting com.android.dex.DexIndexOverflowException: Cannot merge new index 66636 into a non-jumbo instruction!

android {
    ...
    dexOptions {
        jumboMode true
    }
}

If this isn't working, you might have reached method reference limit in dex which is a different issue. You need to use either multidex or proGuard.

thanks, it's working – jesto paul Nov 2 '16 at 8:50

It's work for me. Thanks!!! but what is 'jumboMode' ? Can you please explain me? @Sayooj – D G Sep 20 '18 at 5:21

+120

This is a bug in the merger when the dex files that are being merged have more than 65536 strings. The new index can't fit in a const-string instruction, and the dex merger doesn't support changing instructions if they are different sizes, so it can't be widened to a const-string/jumbo instruction.This was fixed in jb-mr1 by adding a new option: --force-jumbo.This bug can be fixed by adding "dex.force.jumbo=true" to the project.properties.

Not Woking for me – Deepak Sharma Feb 25 '15 at 7:04

@DeepakSharma You have to clean your project after enabling jumboMode – Lilo Sep 9 '15 at 8:07

-10

With latest Android Studio and flag "force jumbo" checked on Android Studio compiler settings, this problem disappear.

If it's possible, add some details in your answer, plz. – shA.t Mar 16 '15 at 4:38

0
votes
answers
19 views
+10

有沒有辦法告訴Android Studio 3.0.1突出異常投擲者?

-1

有沒有辦法告訴過Android Studio 3.0.1突出在代碼的每一個方法可以拋出一個異常?確定在哪裏使用「嘗試 - 抓住」。有沒有辦法告訴Android Studio 3.0.1突出異常投擲者?

沙发
0
0

在拋出必須被捕獲的異常的Java方法(把裏面的try/catch塊),代碼將無法編譯,直到你做的,所以如果你不這樣做,你會得到一個紅線/編譯錯誤。

那些被稱爲檢查例外,例外的是已經被抓住,像IO。

其他異常,未檢查,或運行時異常,一般不應該沒有一個try/catch來處理,但是你需要警惕他們或解決這些問題。

例如,而不是追趕NullPointerException,你應該檢查null如果實例可以null

+0

讓我們舉個例子 「SharedPreferences.getInt(String鍵,詮釋利用DefValue)」。如果存在不是int的此名稱的首選項,則會拋出ClassCastException。如果我不把它放在try/catch塊中,我不會看到紅線/編譯錯誤(Android Studio根本不會將其視爲編譯錯誤)。我想使用try/catch,因爲在「catch」中我想創建可能來自用戶的錯誤的日誌(文本文件)。那麼,有沒有辦法告訴Android Studio 3.0.1突出顯示可以拋出異常的代碼中的每個方法? – Liviu

+0

ClassCastException異常是一種例外,你應該可以解決,而不是「趕」的,確保當你把某些類型的偏好,你獲得的是相同的類型。因爲你無法從這樣的異常中恢復,你會使用什麼值而不是你不能投射的值,這將是不正確的。使用運行時崩潰捕獲這些情況並在開發時修復它們 – elmorabea

+0

謝謝。你說得對。這是一個很好的做法。無論如何,是否有可能告訴Android Studio 3.0.1突出顯示可引發異常的代碼中的每個方法?這是毫無疑問的。 :) – Liviu

4
votes
answers
17 views
+10

How to change name of project in Android Studio

Imported an eclipse project into Android Studio and saved it in a new folder. Changed the package name and everything to new names but the Project's name is still the one from the old project.

How do I change the pointed name into something else?

project name

沙发
+20
  1. 更改清單文件中的名稱。 android:label =“@ string / app_name”
  2. app文件夾中有一個build.gradle文件。從那裡更改包名稱。確保編輯app文件夾中的build.gradle文件,而不是項目根目錄中的build.gradle文件。
板凳
+10

如果您只想更改應用程序的名稱,請輸入src-&gt; main-&gt; res-&gt; values-&gt; strings.xml並將名稱更改為新

地板
+10

您可以在 settings.gradle 文件中嘗試類似的操作:

  rootProject.name =“YOUR_PROJECT_NAME”  

重新啟動Android Studio後,它還會將標題欄中的文字更改為 YOUR_PROJECT_NAME

在Android Studio 2.2 RC2上測試

4楼
0

在settings.gradle文件中更改rootProject.name

  settings.gradle rootProject.name ='NewAppName' 
     
			
        
5楼
-10

Android Studio的Refactor會幫助您。只需單擊重構您的項目即可進行重構

6楼
-10

嘗試更改strings.xml中的 app_name 字符串

&lt; string name =“app_name”&gt;我的應用程序&lt; / string&gt;

按照以下步驟工具.android.com/tech-docs/instant-run - albodelu 2015年12月10日9:32

Android Studio中的新功能(Android Dev Summit 2015)視頻演示它youtu.be/fs0eira2pRY?t=20m52s - albodelu 2015年12月10日14:32