5

I am running AndroidStudio 0.8.4 and have tried this on AndroidStudio 0.8.2.
I am running Java JDK 1.8.0_11 and have tried this with JDK 1.8.0_05.

Whenever I try to build my android studio project -- Build -> Rebuild Project -- or try to run the application, I get the following error:

An exception has occurred in the compiler (1.8.0_11). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.lang.invoke.MethodType not found

Here is my build.gradle in the :mobile module:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-L'
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId "com.energy.dartboard.dartboard"
        minSdkVersion 17
        targetSdkVersion 'L'
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    apply plugin: 'findbugs'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    wearApp project(':wear')
    compile 'com.google.android.gms:play-services:5.0.89'
}

I suspect it to be an issue with Google Play Services because I get the following error when attempting to preview my xml layout file (below) in the Design view with a Google+ sign in button:

java.lang.VerifyError: Expecting a stackmap frame at branch target 15
Exception Details:
  Location:
    com/google/android/gms/common/SignInButton.C(Landroid/content/Context;)V @4: ifnull
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: 2ab4 0016 c600 0b2a 2ab4 0016 b600 262a
    0000010: 2b2a b400 182a b400 15b8 0029 b500 16a7
    0000020: 001c 4d12 0512 04b8 001a 572a 2b2a b400
    0000030: 182a b400 15b8 0022 b500 162a 2ab4 0016
    0000040: b600 232a b400 162a b600 25b6 001b 2ab4
    0000050: 0016 2ab6 001c b1                      
  Exception Handler Table:
    bci [15, 31] => handler: 34

    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
    at java.lang.Class.getConstructor0(Class.java:2803)
    at java.lang.Class.getConstructor(Class.java:1718)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:310)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:100)
    at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:805)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:805)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:500)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:381)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:400)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
    at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:575)
    at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:564)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
    at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:564)
    at com.android.tools.idea.rendering.RenderService.render(RenderService.java:691)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:604)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:80)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:546)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:541)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

And the XML file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.energy.dartboard.dartboard.LoginActivity" >

    <!-- Login Progress -->
    <ProgressBar
        android:id="@+id/login_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:visibility="gone"
    />

    <!-- Login Form -->
    <ScrollView
        android:id="@+id/login_form"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <Button
                android:id="@+id/facebook_sign_in_button"
                android:text="Sign In with Facebook"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
            />

            <com.google.android.gms.common.SignInButton
                android:id="@+id/plus_sign_in_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="32dp"
            />

            <LinearLayout
                android:id="@+id/plus_sign_out_buttons"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:weightSum="2">

                <Button
                    android:id="@+id/plus_sign_out_button"
                    style="?android:textAppearanceSmall"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="@string/plus_sign_out"
                />

                <Button
                    android:id="@+id/plus_disconnect_button"
                    style="?android:textAppearanceSmall"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="@string/plus_disconnect"
                />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/email_login_form"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <AutoCompleteTextView
                    android:id="@+id/email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_email"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true"
                />

                <EditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_password"
                    android:imeActionId="@+id/login"
                    android:imeActionLabel="@string/action_sign_in_short"
                    android:imeOptions="actionUnspecified"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:singleLine="true"
                />

                <Button
                    android:id="@+id/email_sign_in_button"
                    style="?android:textAppearanceSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:text="@string/action_sign_in"
                    android:textStyle="bold"
                />

                <Button
                    android:id="@+id/sign_in_later_button"
                    style="?android:textAppearanceSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/sign_in_later"
                    android:textStyle="bold"
                    android:onClick="signUpLater"
                />

            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

It renders the preview just fine, but without the Google+ Sign in button and with that error message. Other xml layout files without Google Play Services render just fine with no errors.

This project yesterday worked without issues, but as soon as I started up android studio today and tried building it, it gave me this error.

Note: I have tried cleaning/re-building the project, invalidating my cache for android studio, and restarting android studio.

thejava
  • 108
  • 2
  • 10

1 Answers1

2

I don't think android development is yet possible with Java 8. But it surely possible with Java 7. Try to switch to Java 7:

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

I didn't use Android Studio, but I guess that you will also need to change project settings (point it to Java 7 SDK and set language level to Java 7 as well) somewhere else in IDE GUI.

Клаус Шварц
  • 3,158
  • 28
  • 44
  • If this is true, then that is unfortunate because I really enjoy the new stream api and lambda expression support in java 8. I'll try it now. I think I have tried this before, though. – thejava Aug 05 '14 at 23:12
  • You can try Kotlin then :) Regarding your question, I think I am wrong and the problem is not in (only?) in Java 8, but it might be IDE bug. I am not sure I get you correctly, but when do you get error? When you try to load layout xml in UI designer, or when you build project? If second, it should be Java 8, if 1st — it should be IDE bug. – Клаус Шварц Aug 05 '14 at 23:13
  • It's two different errors in two different places. I just clarified it an edit to my question. – thejava Aug 05 '14 at 23:25
  • Ok, the error with `java.lang.invoke.MethodType not found` during build must come from Java 8. The second error is a minor bug in IDE layout renderer that must not affect build. Am I right, that removing **Google+ sign in button** doesn't resolve the issue with "MethodType not found"? – Клаус Шварц Aug 05 '14 at 23:32
  • Good. Try Kotlin language if you wish to enjoy lambdas ^_^ It works for android pretty well and also a product of JetBrains, that develops Android Studio IDE. And have fun :) – Клаус Шварц Aug 05 '14 at 23:40
  • 1
    You were right. It took a while for Android Studio to restart, but it does seem to work once it does (besides a nullpointerexception, but that's an entirely different issue) ;). Anyways, I found a work-around with project retro-lambda that converts java 8 bytecode back to 7 (via some crazy voodoo I don't understand) discussed in [ekcr1's answer to this question](http://stackoverflow.com/questions/23318109/is-it-possible-to-use-java-8-for-android-development) that I'm going to give a try. – thejava Aug 05 '14 at 23:40