-1

Background

Recently Android-Studio has reached RC version, and I thought of giving it (another) try.

This, and the fact that Lollipop was announced, along with nice cool features on Android-Studio.

The problem

I wanted to try out the samples of the new Lollipop version, but as opposed to Eclipse which has the ability to create a project of the API-Demos (which sadly has become "legacy" and has annoyingly more steps to import), I couldn't find how to do it on Android-Studio.

What I've tried

The only thing I've found is single projects, here.

Sadly, not only it's annoying to import them one after another (yet maybe it's better than a huge project), but I've also failed to do it. This is the instructions:

  1. Unpack the downloaded project package.
  2. In Android Studio, chose File > Import Project and select the root folder of the unpacked project. Android Studio may ask you to choose the type of project you are importing. If this is the case, make sure to choose Import project from external model and select the Gradle option.

So, I've taken one sample from here , which is supposed to show how to use the new transition mechanism on Lollipop.

I've opened Android Studio, and I can't find any "File" menu:

enter image description here

I've tried using the "open an existing android studio project" , but this caused this error: enter image description here

I've also tried other solutions, such as creating a new Android app and import the other project, and also use "import non android studio project". I've even tried importing it to Eclipse (and succeeded), but then it crashed on this exception:

11-23 18:07:20.950: E/AndroidRuntime(2141): Process: com.example.android.activityscenetransitionbasic, PID: 2141
11-23 18:07:20.950: E/AndroidRuntime(2141): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.activityscenetransitionbasic/com.example.android.activityscenetransitionbasic.MainActivity}: java.lang.RuntimeException: Unknown scene name: moveImage
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.access$800(ActivityThread.java:144)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.os.Handler.dispatchMessage(Handler.java:102)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.os.Looper.loop(Looper.java:135)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.main(ActivityThread.java:5221)
11-23 18:07:20.950: E/AndroidRuntime(2141): at java.lang.reflect.Method.invoke(Native Method)
11-23 18:07:20.950: E/AndroidRuntime(2141): at java.lang.reflect.Method.invoke(Method.java:372)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
11-23 18:07:20.950: E/AndroidRuntime(2141): Caused by: java.lang.RuntimeException: Unknown scene name: moveImage
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:177)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:181)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.transition.TransitionInflater.inflateTransition(TransitionInflater.java:77)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.policy.impl.PhoneWindow.getTransition(PhoneWindow.java:3696)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3657)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:367)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.Activity.setContentView(Activity.java:2144)
11-23 18:07:20.950: E/AndroidRuntime(2141): at com.example.android.activityscenetransitionbasic.MainActivity.onCreate(MainActivity.java:47)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.Activity.performCreate(Activity.java:5933)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
11-23 18:07:20.950: E/AndroidRuntime(2141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)

The question

How do I really import sample apps into Android-Studio?

Is the new website the new, official way to do it?

Also, how do I do it correctly for Eclipse? It seems to be missing SMS handling classes/functions on the files "MmsMessagingDemo.java" and "MmsWapPushReceiver.java". Only if I make them as comments, it compiles fine.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Why the downvote? At least give an explanation of what I did wrong here... – android developer Nov 23 '14 at 19:39
  • No, no. Don't try to import. The sample api-demos should be much easier to install using the Android Studio wizard. Which one? I don't remember. May be, when I get to my other computer, I'll find out for you if the question is still unresolved by then. PS: I'm not the one who downvoted you. I'm not sure either why someone did that. – Stephan Branczyk Nov 24 '14 at 23:33
  • Ah! the downvote may be due to the gradle plug-in error message. Just focus on that problem right now. Do a google search on the exact gradle error you're getting. If you can solve that problem, it may solve your other problems (whether you use the new android project wizard to clone and open a sample application, or whether you import it manually by going through the samples directory structure of the android sdk). – Stephan Branczyk Nov 24 '14 at 23:38
  • @StephanBranczyk But this is a questions for both IDEs, using the latest version... Why would it have an issue? – android developer Nov 24 '14 at 23:49
  • Regarding the downvote, I don't know. Anyway, did you try solving your gradle issue? If I were you, I'd download and re-install Android Studio with the SDK a second time, I'd change the default channel from Canary to Stable, verify the environment variables for android sdk, update Android Studio, update your build-tools & sdk/code samples for your target sdk using the sdk manager, and then I'd press on "Start a New Project" to start from a sample. If you still get a gradle error, it's easier for us to google it if you give us the actual text from your clipboard, instead of a screenshot. – Stephan Branczyk Nov 25 '14 at 01:44
  • And no, this question is not for both IDEs. Moving from one IDE to the other IDE has potential problems each time you do it. That is why I'm suggesting that you reinstall the android sdk and Android Studio from scratch to make sure none of the api demo samples and existing workspaces are contaminated with legacy configurations. – Stephan Branczyk Nov 25 '14 at 01:50
  • @StephanBranczyk Shouldn't the RC version be able to create the samples? I expected it to be more stable than others... The question is for both IDEs, as on both I had a problem importing the API demos. The Android SDK (and all the other apps) was installed on a clean PC that I've bought recently. It can't be any cleaner than that... :) – android developer Nov 25 '14 at 06:30
  • @StephanBranczyk Anyway, about Eclipse, the problem is that it contains at least 2 classes that try to access SMS related classes, which do not exist on Android API. Perhaps it's a bug. I've made the classes as comments, and now it works on Eclipse. However, I still wish to know why it doesn't work there, and how to do it on Android-Studio. I've now put an older "stable" version of Android-Studio, and I still can't find where to create the API demos (it's not in the creation of a new project, like on Eclipse) . Not only that, but it tells me there is an update to the RC version. – android developer Nov 25 '14 at 07:31
  • @StephanBranczyk The problematic classes for Eclipse are "MmsMessagingDemo.java" and "MmsWapPushReceiver.java" BTW. The rest of the issues were solved by using the support library. – android developer Nov 25 '14 at 07:34

2 Answers2

0

Check out this link it contains a solution for moveImage error:

It says

  moveImage should be replaced by changeBounds and changeImageTransform

Like this:

  <?xml version="1.0" encoding="utf-8"?>

<!-- changeBounds is used for the TextViews which are shared -->
<changeBounds>
    <!--
        Set this transitions target IDs to be those which point to the TextViews in both the
        starting and result Activities
    -->
    <targets>
        <target android:targetId="@id/textview_name" />
        <target android:targetId="@id/textview_title" />
    </targets>
</changeBounds>

<!-- moveImage is used for the ImageViews which are shared -->
<changeImageTransform>
    <!--
        Set this transitions target IDs to be those which point to the ImageViews in both the
        starting and result Activities
    -->
    <targets>
        <target android:targetId="@id/imageview_header" />
        <target android:targetId="@id/imageview_item" />
    </targets>
</changeImageTransform>

Go to:

  res>>>transition>>> edit your transition xml file and change <moveImage> to <changeImageTransform>

And make sure to check the ids in "target" tag; you must have them in your layout.

Amt87
  • 5,493
  • 4
  • 32
  • 52
  • I don't understand. What should be fixed, and why isn't the sample fixed and ready to be imported ? – android developer Nov 26 '14 at 14:11
  • I have edited the answer, may it be helpful. From the link I see that there is a problem in this sample so they edited it and moved it to another repository. But API samples are not updated yet. – Amt87 Nov 27 '14 at 07:08
  • I see. I've changed it and it works, but still, how can I check all of the samples? One by one? or is there an API demos for Android-Studio too? and if so, how do I import it? Does it include those on the website I've posted about? – android developer Nov 27 '14 at 20:46
0

This is what you should put instead of moveImage:

<changeBounds>
    <targets>
        <target android:targetId="@id/imageView_image" />
        <target android:targetId="@id/imageView_image" />
    </targets>
</changeBounds>

<changeImageTransform>
  <targets>
        <target android:targetId="@id/imageView_image" />
        <target android:targetId="@id/imageView_image" />
    </targets>
</changeImageTransform>
thekadrik
  • 26
  • 2
  • Please tell me, step by step, what to do. – android developer Nov 26 '14 at 23:13
  • As I can see you have successfully build the application, so the only thing to do is to remove the element ` ` in grid_detail_transition.xml, and replace it with the one from the answer above. – thekadrik Nov 27 '14 at 00:31
  • OK, I've changed it for this sample, and it didn't work as it doesn't know what "imageView_image" is, so I've only replaced the "moveImage" to "changeImageTransform". This worked, but the main question is how to import the API demos. Also, I assume this fix won't work for each of the samples on the website I've written, right? – android developer Nov 27 '14 at 20:47
  • Yes, you are right, it depends from sample to sample. I've imported few of them and had to deal with various problems to get them work, most of them due to old gradle version (I am running Android Studio RC2 with newer version of the gradle build system). Hopefully, Google will release an update to the API samples soon – thekadrik Nov 27 '14 at 21:12
  • I see. Thank you anyway. Do you know how to import the API demos though? – android developer Nov 27 '14 at 22:36