What Is the Proper Project Configuration for the N

2019-04-20 14:13发布

问题:

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?

回答1:

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.



回答2:

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
    }
}


回答3:

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
    }

...
}


回答4:

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.


回答5:

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.