11

The docs claim a build.gradle like this works:

android {
  compileSdkVersion 'android-N'
  buildToolsVersion 24.0.0
  ...

  defaultConfig {
     minSdkVersion 'N'
     targetSdkVersion 'N'
     ...
  }
  ...
}

That gives me failed to find Build Tools revision 24.0.0, when using 'com.android.tools.build:gradle:1.5.0' for the Android Plugin for Gradle and Gradle 2.5.

If I look in build-tools/ in my Android SDK installation, I see 24.0.0-preview, not 24.0.0. However, if I switch my build.gradle to use buildToolsVersion "24.0.0-preview", I get Invalid revision: 24.0.0-preview.

So, what combination of build.gradle values works to build a project to compile against the N Developer Preview SDK?

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • is your emulator running with N images ? Mine crashes at start up – Vivek Mishra Mar 10 '16 at 18:04
  • I have the x86 emulator working (I haven't tried the x86_64 one), though I am doing more of my testing on hardware. – CommonsWare Mar 10 '16 at 18:06
  • Why anyone would go for `Android N` as google have already said that its not a stable version until unless `Android N beta` released. – Pankaj Mar 10 '16 at 18:20
  • @Clairvoyant: Testing your apps on developer previews is fairly important. For example, your app might behave poorly as the user resizes the window using N's multi-window feature. Or, there may be specific things in the new version that you want to start developing now, so that once N ships in final form, you are ready to deploy an updated app (e.g., scoped directory access to give you better options for removable storage). If you want to wait for a later developer preview, that's your call. – CommonsWare Mar 10 '16 at 18:23
  • But the thing is your OS might not work properly and you would think that your code or configuration is not correct. `Beta` version would give stability to your OS. `Preview` version is mainly for testing of device for New OS. – Pankaj Mar 11 '16 at 05:24
  • @ [this link](http://developer.android.com/preview/overview.html) u can see its an alpha version and rest preview version would be beta versions. – Pankaj Mar 11 '16 at 18:16

5 Answers5

4

Based on one of the sample apps, I am now using:

  • Gradle 2.10
  • 'com.android.tools.build:gradle:2.1.0-alpha1' for the Android Plugin for Gradle (goes in your top-level build.gradle file)
  • buildToolsVersion "24.0.0 rc1"

This seems to be holding up, including with Android Studio 1.5.1.

UPDATE: Now that N Developer Preview 4 has been released, we can start using 24 in place of "N" and "android-N":

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 24
    }
}
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
3

I believe issue occurred because of using buildToolsVersion 24.0.0.

According to official set up guide, use:

  compileSdkVersion 'android-N'
  buildToolsVersion '24.0.0 rc1'

  defaultConfig {
    minSdkVersion 'N'
    targetSdkVersion 'N'
    ...
  }

Note that minSdkVersion other than 'N' works as well, but you'll have to use 'N' device to run your app anyways.

Gradle 2.4 works for me. Also you don't have to use 'com.android.tools.build:gradle:2.1.0-alpha1' as it is mentioned in preview samples. Using classpath 'com.android.tools.build:gradle:1.5.0' works as well.

 dependencies {
     classpath 'com.android.tools.build:gradle:1.5.0'
     ...
 }

Don't forget to get the Java 8 JDK and JRE. It is required to make it work on 'N', but you can set sourceCompatibility JavaVersion.VERSION_1_7 and targetCompatibility JavaVersion.VERSION_1_7 if not using Java 8 features.

Note: Using the new Java 8 language features is not a requirement for developing apps that target the Android N platform. If you don't want to write code with Java 8 language features, you can keep your project's source and target compatibility values set to Java 7, but you still must compile with JDK 8 to build against the Android N platform.

Check Java 8 Language Features for details.

Ivan V
  • 3,024
  • 4
  • 26
  • 36
1

I seem to be rolling pretty well with this config on a new project with a PixelC:

android {
    compileSdkVersion 'android-N'
    buildToolsVersion '24.0.0 rc4'

    lintOptions {
        abortOnError false
    }


    defaultConfig {
        minSdkVersion 'N'
        targetSdkVersion 'N'

        jackOptions {
            enabled true
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

...
}
0

Based on Sample project you have to use

android {
    compileSdkVersion 'android-N'
    buildToolsVersion '24.0.0 rc1'

    defaultConfig {
        applicationId "com.android.multiwindowplayground"
        minSdkVersion 'N'
        targetSdkVersion 'N'
  ....

    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
  • Android Studio 2.1 Preview
  • Use gradle-2.10-all.zip
  • com.android.tools.build:gradle:2.1.0-alpha1 for the Android Plugin for Gradle (goes in your top-level build.gradle file)
  • buildToolsVersion "24.0.0 rc1"
  • Select N: Android API 23, N Preview (Preview). Its working for me.
Maheshwar Ligade
  • 6,709
  • 4
  • 42
  • 59
  • You do not need Android Studio 2.1. Also, [there does not appear to be a `2.1.0-alpha9` edition of the Android Plugin for Gradle](https://bintray.com/android/android-tools/com.android.tools.build.gradle/view),at least at this time. – CommonsWare Mar 10 '16 at 17:59
  • @CommonsWare You need Android Studio 2.1 to run N. It is clearly written in this link https://developer.android.com/preview/setup-sdk.html – Vivek Mishra Mar 10 '16 at 18:07
  • 1
    @VivekMishra: I am sitting here, with Android Studio 1.5.1, and I am perfectly capable of running Android N projects on an Android N device, given the project configuration from my answer. Android Studio 2.1 is needed for Java 8 support, should you choose to use that. – CommonsWare Mar 10 '16 at 18:11
  • @CommonsWare Android Studio2.1 is for JDK 8. if you want to use JDK 7 then Android studio 1.5 + version you can use right. I have JDK 8 with android Studio 2.1 it works – Maheshwar Ligade Mar 10 '16 at 18:14
0

The problem is that you can not put minSdkVersionless than "N". if you put a smaller version, or receive error, or go only +23 devices.

diaconu liviu
  • 1,032
  • 2
  • 13
  • 30
  • Thats not true. I have 8 as min SDK: minSdkVersion 8 targetSdkVersion 'N' – Phyrum Tea Mar 10 '16 at 22:29
  • I can make 17 but when I try to install the emulator receive error . 23+ only say . then it may be an error of windows . – diaconu liviu Mar 10 '16 at 22:32
  • 1
    that's not quite right. Basically you can use any version for minSdkVersion, but you will still need an "N" device to run the app. – Ivan V Mar 16 '16 at 12:40