How to resolve : unexpected error occured Initiali

2020-02-17 01:57发布

问题:

Bringing up a new PC with Xamarin and VS 2015 Pro I received the following error:

An unexpected error occurred trying to initialize Android Designer. Please verify the Android SDK path and the Java Development Kit path on Tools->Options->Xamarin->Android Settings menu. Please see the logs for more details.

I verified the SDK's are installed correctly. VS didn't generate any kind of Activity Log so I believe the log must lie elsewhere. Anyone know where I can find this log to find out more about what is wrong ?

回答1:

I had exactly the same problem described (on a new PC, with a new Visual Studio install) and am 99.9% sure the answer is in how updates are applied. Or, more importantly, how they aren't being applied when you think they are.

  1. Go to Tools | Options | Xamarin | Other, and under Xamarin for Visual Studio Updates, Check now for STABLE updates. Make sure you're running at least 4.2.0.680. You will have to close Visual Studio in the background as the updater is running--it'll warn you. Uninstalling and installing the cross-platform development tools from Visual Studio was not applying this update for me. I had to force the issue.

  2. Now, as mentioned earlier, go to Tools, Android SDK Manager. I noticed my "Android SDK Tools" and "Cross Platform Tools" were out of date and updates were available. I accepted and applied the updates to version 24.4.1. BEAR WITH ME, THIS IS WHERE IT GETS TRICKY--it still didn't work.

  3. Go back to Tools, Android SDK Manager. I immediately noticed that even though I'd just applied the latest update for "Android SDK Tools", (24.4.1), a new version (25.2.2) was now available, along with 17 other updates. I accepted them all.

  4. Bingo. Where I once had the annoying error message and an empty design surface and an empty toolbox with the sad "no usable controls" message, I now have the attached screen snapshot--a design surface where I can see a visual representation of my .axml, and a toolbox from which I can drag and drop controls and they actually show up on my Samsung tablet.

Sorry so verbose. I lost hours on this problem and thought others might appreciate another working solution.



回答2:

I had a similar problem as explained below. Here a solution that worked for me:

1) delete the one package appearing in the screen shot below. Nota bene: At this stage VS 2015 greyed out the Android SDK manager buttons, even after a restart.

2) download installer_r24.4.1-windows.exe for windows https://developer.android.com/studio/index.html

3) launch the Android SDK Manager outside of VS and install the proposed 19 packages. This time I could go through the installation.

4) Launch VS 2015 and create Xamarin Android project. Launching Main.axml would launch the designer properly on an android project.

The bug I had

I had the same problem here on a fresh install of Win10 + Full visual studio community 2015 update 3 + .Net Core + Azure SDK and Xamarin. Creating a new project Xamarin Native (iOs + Androird) shows up the same message as mentioned by MikeJ. In addition, running in debug F5 makes the designer have a new popup

Problem seems to appear also here https://bugzilla.xamarin.com/show_bug.cgi?id=44374 and here https://forums.xamarin.com/discussion/77669/how-do-i-fix-this-error-the-installed-android-sdk-is-too-old-version-25-1-3-or-newer-is-required .

Opening the Android Manager does not show up version 25 as an option, instead it shows this

However, we cannot install (greyed out button even by accepting license)

Updating Xamarin did not work neither How to update Xamarin for Android within Visual Studio Community 2015

Some guidance would be great to understand what happened.



回答3:

I had the same problem (when bringing up a new PC with Xamarin) and after a few days I solved the problem.

I moved sdk directory from "C:\Program Files (x86)\Android\android-sdk" to "C:\android-sdk". Then I opened the sdk manager and made updates. It's all.

I think the problem is with the path, which has space :)



回答4:

I was able to to fix the issue by opening the Android SDK Manager and updating all the tools to the latest version.



回答5:

If you are already using Android Studio in your computer then this might solve your problem. Check whether SDK is already available at some other location. That worked for me. To check SDK path- Open Android Studio-> Click on SDK Manager Icon. Check Android SDK Location. Copy that path.

In Visual Studio-- Open Tools->Options->Xamarin->Android Settings menu and replace the new SDK path. It will automatically ask to download the updates. Install all packages and you are done!



回答6:

before you go through all that trouble (and I went through many convoluted steps myself for several hours) please try run your VisualStudio as administrator and see what happens!

It solved the above issue (and then some) for me. I used fresh WIN 10 and VS2015 Community install and I must have set some of my permissions to tight.

Also I learned that updating my NuGet package: Xamarin.Forms (v.2.3.3.168) solved errors related to:

System.MissingMethodException: Method Android.Support.V4.Widget.DrawerLayout.AddDrawerListener not found.

But that is another issue all together.



回答7:

Adding these two references to Droid.csproj and packages.config fixed the problem for me:

<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />

<package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />


回答8:

Another issue to be aware of is that you need to have Java Development Kit 8 referenced in Xamarin, instead of JDK 7. You can set this is Tools > Options > Xamarin > Android.