Domanda

Non riesco a ottenere le mie applicazioni Android per compilare a causa di un'eccezione davvero fastidiosa da Android Studio:

] ()! [Inserisci Descrizione dell'immagine qui

Execution failed for task ':myapp-services:compileDebugJava'.
    Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
.

Sono su Ubuntu 12.04, e sto eseguendo Oracle's Java 7 JRE / JDK.

in ~/.bashrc:

export JAVA_HOME="/usr/lib/jvm/java-7-oracle/"
.

in android-studio/bin/studio.sh:

export JAVA_HOME="/usr/lib/jvm/java-7-oracle/"
.

Uscita di javac -version:

javac 1.7.0_51
.

Uscita di java -version:

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
.

Uscita di printenv JAVA_HOME:

/usr/lib/jvm/java-7-oracle
.

Uscita di which javac:

/usr/bin/javac
.

Ho anche disconnesso e registrato nuovamente nella mia sessione.

Non sono davvero sicuro di cosa mi manchi qui.Perché Android Studio non può compilare la mia applicazione?

È stato utile?

Soluzione 2

Ho trovato una soluzione in Una risposta diversa :

rm ~/.AndroidStudioPreview/config/options/jdk.table.xml
.

Che cosa sembra essere accaduto è che qualcosa è stato configurato per una versione precedente di Android Studio e questa configurazione ha vissuto troppo a lungo :)

Altri suggerimenti

L'ho risolto aggiornando build.gradle (livello superiore) con

classpath 'com.android.tools.build:gradle:2.1.2'
.

Anche stavo ricevendo questo errore. Dopo molte ore cercando di risolverlo, sono riuscito a risolvere il problema.

Nel mio caso, l'esecuzione dell'app dalla riga di comando ha fatto il trucco!

Ecco cosa ho fatto (sto usando Windows 10). Si prega di eseguire questi comandi sulla radice del progetto (dove abbiamo la directory app ):

1) gradlew assembleebug

    .
  • Gradle eseguirà i suoi compiti e dovresti vedere il messaggio: Build Build di successo

2) ADB Install -r App \ Build \ Uscite \ APK \ app-debug-non allineata.apk

    .
  • Dopo aver eseguito questa linea, vedrai il messaggio: [100%] /Data/Local/tmp/app-debug-unigned.apk PKG: /Data/Local/tmp/app-debug-unigned.apk. Successo

3) Shell ADB AM START -N Pacchetto_Name / Package_Name.Mainattività , dove "Package_name" deve essere sostituito dal nome del pacchetto (puoi trovarlo su AndroidManifest.xml). Se la "mainattività" non è la tua attività di avvio, sostituirla con la propria attività.

    .
  • Vedrai il messaggio: Avvio: INTENT {CMP= Package_Name / .Mainattività} , dove "package_name" è il tuo nome del pacchetto dell'app.

Installerà l'app sul tuo dispositivo e successivamente, Android Studio sembra trovare nuovamente la variabile Java_Home. Dovresti essere in grado di eseguire l'app colpendo il pulsante "RUN" su Android Studio.

Spero che aiuti qualcuno!

L'ho risolto aggiornando classpath di (build.gradle (progetto: ProgettoName))

classpath 'com.android.tools.build:gradle:2.2.3' 
.

update build.gradle module

    classpath 'com.android.tools.build:gradle:3.0.1'

Solved my issue

Go To Settings->Project Structure->JDK path and change it to the system JDK instead of Studio JDK, you will be up and running.

Just downloaded the latest version (android-studio-ide-1641136.dmg) and I just changed the Info.plist file content. It's originally configured to use 1.6* as of Java version. I have 1.8 installed, so just changed to 1.8* and worked.

I am on Mac Yosemite.

I have found a problem with the Android Studio studio.bat file and here it is

    ::------------------------------------------------------
    :: Locate a JDK installation directory which will be used to run the IDE.
    :: Try (in order): ANDROID_STUDIO_JDK, ..\jre, JDK_HOME, JAVA_HOME.
    :: ---------------------------------------------------------------------
    IF EXIST "%ANDROID_STUDIO_JDK%" SET JDK=%ANDROID_STUDIO_JDK%
    IF NOT "%JDK%" == "" GOTO jdk
    IF EXIST "%~dp0\..\jre" SET JDK=%~dp0\..\jre
    IF NOT "%JDK%" == "" GOTO jdk
    IF EXIST "%JDK_HOME%" SET JDK=%JDK_HOME%
    IF NOT "%JDK%" == "" GOTO jdk
    IF EXIST "%JAVA_HOME%" SET JDK=%JAVA_HOME%
    IF "%JDK%" == "" GOTO error

Do you get the problem in the last 2 lines of code?
It seems that if your environmental variable is %JAVA_HOME% the batch file will GOTO error and an error message will be displayed and that's it NO ANDROID STUDIO FOR YOU, even though %JAVA_HOME% contains a valid path but if the environmental variable is something like %ANDROID_STUDIO_JDK% like mine is because I created it myself then it will work


PROPOSED SOLUTIONS

(1) Edit the batch file Where you see this IF EXIST "%JAVA_HOME%" SET JDK=%JAVA_HOME% IF "%JDK%" == "" GOTO error
Change it to this
IF EXIST "%JAVA_HOME%" SET JDK=%JAVA_HOME% IF NOT "%JDK%" == "" GOTO jdk IF "%JDK%" == "" GOTO error
(2) Create an environmental variable named %ANDROID_STUDIO_JDK% as shown here https://kb.wisc.edu/cae/page.php?id=24500

Check echo $JAVA_HOME

if it doesn't gives you correct path. follow setting JAVA_HOME path on Ubuntu

if it gives you correct path set then you need to update your gradle plugin version (It worked for me) and rebuild project.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top