LoginSignup
3
2

More than 3 years have passed since last update.

Visual Studio 2019 で Xamarin.Android アプリをエミュレータで実行すると "ポートの転送に失敗しました" というエラーが出るときの対処

Posted at

Visual Studio 2019 で Android アプリのプロジェクトを作成し(Xamarin.Forms でも Xamarin.Android でも)、エミュレータで実行すると、次のエラーが出ました。

アプリケーションの開始エラー: ポートの転送に失敗しました。
デバッガーに接続できませんでした。詳細については Xamarin 診断出力を、
例外の詳細についてはログをご覧ください。

プロジェクトのビルドは成功しており、エミュレータの起動も完了しているにも関わらず、です。

このような場合、日本語のエラーメッセージで検索しても解決できる可能性は低いので、まずは英語のエラーメッセージを表示するために、Visual Studio の言語設定を英語にしましょう。

VS2019 を英語にするには、まずは英語の「言語パック」をインストールする必要があります。

  1. Visual Studio Installer を起動します
  2. 言語パック → 英語 にチェックを入れてインストールします

image.png

次に Visual Studio 2019 の設定で言語を変えます。

  1. Visual Studio 2019 のメニュー → ツール → オプション
  2. 環境 → 国際対応の設定 → 「English」を選択

image.png

これで同じ手順を辿ると、エラーメッセージは次のような英語になります。

Error Starting Application: Failed to forward ports.
Couldn't connect debugger. You can see more details in Xamarin Diagnostic output and the full exception on logs.

英語でググるとなんとか解決策に辿り着けるでしょう。

I've solved the problem! I deleted platform-tools in the SDK folder. And replaced it with an older version - platform-tools_r28.0.2-windows.zip. It all worked! Both from VS 2017 15.9.7 and after upgrading to 15.9.16. VS 2019 16.2.5 also successfully works with platform-tools_r28.0.2. Conclusion! - It is not the studio's fault, but the update of platform tools from android sdk to version 29 (29.0.1, 29.0.2 - does not work with VS 2017/2019, 28.0.2 - successfully works!)

Android SDK 内の platform-tools のバージョンが新しすぎると発生するから、古いバージョンにダウングレードすると回避できる、とのこと。

古いバージョンとはこちら → platform-tools 28.0.2

28.0.2 の platform-tools に置き換えて、Visual Studio 2019 を再起動、プロジェクトとエミュレータを再ビルド&実行すると、正常にエミュレータにアプリが転送できました。

ちなみにこのエラーが出たとき、私の platform-tools は 28.0.3 でした。
おそらく、Android SDK を Android Studio と共有していて、Android Studio 側で SDK をアップデートしたために、Visual Studio が対応していない 新しすぎる バージョンに更新されたためと思われます。

ディスク容量節約のために SDK を共有していますが、このようなリスクもある事を頭に入れておきましょう。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2