Question

I have two errors that I think relate to the same issue, so I'm posting this as a single question. If there are multiple causes, I can repost as two questions.

Both of these two lines preceding the class declaration have errors.

import android.security.KeyPairGeneratorSpec; 
//The import android.security.KeyPairGeneratorSpec cannot be resolved

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
//JELLY_BEAN_MR2 cannot be resolved or is not a field

public class AndroidKeyStoreUtil {

...

}

In my manifest, I have this:

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

I'm current on my SDK installations up through API 19 and I'm compiling with Java 1.6. Do the newer Android APIs require Java 7, maybe? I can't get that to work in Eclipse.

Any idea why this is happening? Thanks!

Was it helpful?

Solution

Just stumbled on the solution to this. The suggestions of others are definitely required. Specifically, make sure that you have the manifest set to target sdk of 18 (or higher) and also make sure that your Android SDK Manager is current on all updates.

But what was still not solving it for me was simply that I need to update my Project Build Target to at least 4.3 (I was still on 4.2.2). Here is how to do this:

Right-click on the project and select Properties
Click Android
Change Build Target to Android 4.3 (or higher)

Simple fix once I noticed the problem.

OTHER TIPS

I had the same issue, but in my case I had the sdk target/min correctly setup:

 <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="19" />

I'm working on an Android-Maven project but the same solution may apply to other types of projects. In my case the problem happened because of wrong dependency. I was using the android dependency provided by Maven Central Repository (which is older than the one I need):

 <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>4.1.1.4</version>
        <scope>provided</scope>
    </dependency>

So I used the Android SDK Deployer to get the API 19 one and changed my dependency to:

 <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <version>4.4.2_r3</version>
        <scope>provided</scope>
    </dependency>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top