Android Schematic内容提供程序库配置? [英] Android Schematic content provider library configuration?

查看:75
本文介绍了Android Schematic内容提供程序库配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jake Wharton在最近的一次演讲中提到了这个库,它看起来像是避免大量样板的好方法,所以我给了它一个机会.但是没有任何成功. https://github.com/SimonVT/schematic

Jake Wharton mentioned this library in a recent talk and it looks like a great way to avoid a load of boilerplate so I gave it a go. But without any success. https://github.com/SimonVT/schematic

下面是内容提供者的定义,其中附加了注释和清单提供者元素.问题是Android Studio不喜欢提供程序定义,因为内容提供程序类没有扩展ContentProvider.

Below is the definition of the content provider with the annotation attached and the manifest provider element. The issue is that Android Studio does not like the provider definition because the content provider class does not extend ContentProvider.

Caused by: java.lang.ClassCastException: com.myapp.SchematicContentProvider
cannot be cast to android.content.ContentProvider

我想念什么?它可能与我未使用的android-apt有关(原理图推荐它,但似乎并不需要它)-当我尝试使用android-apt时,我收到一个VerifyError,因此必须将其从构建中删除.

What am I missing? It could be related to android-apt which I am not using (Schematic recommends it but does not seem to require it) - when I try using android-apt I get a VerifyError so had to remove it from the build.

AndroidManifest.xml

AndroidManifest.xml

    <provider
        android:name="com.myapp.SchematicContentProvider"
        android:authorities="com.myapp.provider"
        android:exported="false" />

以及类定义:

import net.simonvt.schematic.annotation.ContentProvider;
import net.simonvt.schematic.annotation.ContentUri;
import net.simonvt.schematic.annotation.TableEndpoint;

@ContentProvider(authority = SchematicContentProvider.AUTHORITY, database = SchematicDatabase.class)
public class SchematicContentProvider {

    public static final String AUTHORITY = "com.myapp.provider";

    interface Path {
        String ROUTES = "routes";
    }

    @TableEndpoint(table = SchematicDatabase.ROUTES) public static class Routes {

        @ContentUri(path = Path.ROUTES, type = "vnd.android.cursor.dir/list", defaultSort = SchematicRouteColumns.TITLE + " ASC")
        public static final Uri ROUTES = Uri.parse("content://" + AUTHORITY + "/" + Path.ROUTES );
    }

}

我已经浏览了Schematic示例应用程序(自述文件中的代码片段是局部的),但看不到我错过的内容.我不确定如何确认代码生成正常,如何检查?我查看了build下的内容,但仅在Schematic包名称下看到了BuildConfig.

I've looked through the Schematic sample app (the code snippets in the readme are partial) but I can't see what I've missed. I'm not sure how to confirm that the code generation is working, how do I check? I looked under build but I only see BuildConfig under the Schematic package name.

可惜的是没有为我工作,它有很大的潜力.

It's a shame it's not working for me, it has great potential.

推荐答案

您没有在声明正确的ContentProvider. 您必须在清单中声明生成的一个. 我应该这样:

You aren't declaring the right ContentProvider. You have to declare the generated one in the Manifest. I should like this :

<provider
    android:name=".yourOptionalPackage.generated.SchematicContentProvider"
    android:authorities="com.myapp.provider"
    android:exported="false" />

如果您的IDE(Android Studio/IntelliJ)显示红色警告,只需单击生成项目"按钮以生成代码.

If your IDE (Android Studio/IntelliJ) shows red warning, just click on the Make Project button to generate the code.

如果仍然无法使用,请在您的项目中包含apt-lib(值得),并节省更多时间,请使用此很棒的库也是基于apt-libs的;)

If it's still not working, include apt-libs in your project (worth it), and to save even more time, use this awesome library also based on apt-libs ;)

在评论中让我知道我是否解决了您的问题,以及是否需要帮助配置gradle文件.

Let me know in the comments if I solved your problem or not, and if you need help configuring your gradle file.

这篇关于Android Schematic内容提供程序库配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆