简体   繁体   中英

How to ignore @JavascriptInterface annotation with builds under API 17 -Android

The @JavascriptInterface annotation works on api 17 and above. For my project the annotation cannot be found as my target api is set to 13:

我的项目构建目标

and in my manifest the min sdk is 11:

 <uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="18" />

Why do I have to go into the project build target (eg, Project > Properties > Android in Eclipse) and change it to API 17+ as a resolution. Now I have to build against that SDK when all I really want to do is ignore the annotation on anything below API 17. Is there anyway I can do that? I dont like the idea of building against api 17 and then later finding out I have code that wont run on prior releases. My goal is to ensure my app can run on api 13 to 18. If commonsWare is around maybe he can suggest something I'm missing...

For my project the annotation cannot be found as my target api is set to 13:

Then fix that, or set your android:targetSdkVersion low enough that you do not need @JavascriptInterface .

Why do i have to go into the project build target (eg, Project > Properties > Android in Eclipse) and change it to API 17+ as a resolution.

Because @JavascriptInterface does not exist prior to API Level 17, just as DisplayManager does not exist prior to API Level 17.

Now i have to build against that SDK when all i really want to do is ignore the annotation on anything below API 17.

Since your build target does not affect anything other than what classes, methods, annotations, etc. are available to you, I fail to see the concern.

I dont like the idea of building against api 17 and then later finding out i have code that wont run on prior releases.

Lint has been reporting API level violations for well over a year. Just make sure your android:minSdkVersion is set properly.

After all, you were already relying upon this , as your android:minSdkVersion is set to 11 and your build target is presently set to 13. That means that you are counting Lint to report where you are using API Level 12 and API Level 13 APIs so that you can handle them properly. All you are doing by raising the build target is raising the number of things that you are relying upon Lint for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM