Android Studio - AppIndex URI

5
我最近升级了Android Studio到2.1版本,并将我正在工作的项目更新到Gradle版本2.1.0。 我注释掉了我的代码中一个与自动生成的App Indexing代码无关的行,现在,每当我尝试运行我的应用程序时,它就会崩溃并给出以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{lux.unisabana.sabanaviveenti/sabanaviveenti.unisabana.lux.unisabana.appsabana.MainActivity}: java.lang.IllegalArgumentException: AppIndex: The android-app URI host must match the package name and follow the format android-app://<package_name>/<scheme>/[host_path]. Provided URI: android-app://sabanaviveenti.unisabana.lux.unisabana.appsabana/http/host/path

我已经四处寻找并尝试了很多方法,更新目标版本、所需库等等,但迄今为止仍然没有解决,有人可以帮助我吗?

我用于编译的SDK版本是23,使用的Google服务依赖项是8.4.0。


你在URI主机中放了什么?你的包名是什么? - Mr.Rebot
正如我所说,代码是自动生成的,但这里是它的内容:Action viewAction = Action.newAction( Action.TYPE_VIEW, "主页", // TODO: 如果您有与此应用程序活动内容匹配的网页内容, // 请确保此自动生成的网页URL正确。 // 否则,将URL设置为null。 Uri.parse("http://host/path"), // TODO: 确保此自动生成的应用程序URL正确。 Uri.parse("android-app://sabanaviveenti.unisabana.lux.unisabana.appsabana/http/host/path") ); AppIndex.AppIndexApi.start(client2, viewAction); - Jpfcan
1个回答

3

我也曾为这个问题奋斗了将近两天。 简单来说:在你的Java文件中搜索“sabanaviveenti.unisabana.lux.unisabana.appsabana/http/host/path”。你很可能会在初始活动的OnStart()方法中找到它们。 你需要用包含你主要应用程序代码的包名替换sabanaviveenti.unisabana.lux.unisabana.appsabana。例如,像这样:

    Action viewAction=Action.newAction(
            Action.TYPE_VIEW, // TODO: choose an action type.
            "LogTasks Page", // TODO: Define a title for the content shown.
            // TODO: If you have web page content that matches this app activity's content,
            // make sure this auto-generated web page URL is correct.
            // Otherwise, set the URL to null
            Uri.parse("http://host/path"),
            // TODO: Make sure this auto-generated app URL is correct.
            // was: Uri.parse("android-app://sabanaviveenti.unisabana.lux.unisabana.appsabana/path"),
            Uri.parse("android-app://com.myserver.mypackage/http/host/path")
    );
    AppIndex.AppIndexApi.start(client, viewAction);

我遇到问题的原因是因为我正在重构应用程序的代码,并同时更新Android Studio和SDK。某种方式下自动生成了这段代码。在我的情况下,活动位于库包中,但应用程序中的主活动派生自此活动,因此我没有直接看到原始活动代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接