我试图在我的gradle项目中添加一些信号。
但是我收到以下错误:
build file '/tmp/workspace/myapp-develop/My_app/android/app/build.gradle': 196: only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
我的gradle app build.gradle文件如下所示:
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
configurations.all {
resolutionStrategy.force 'com.google.android.gms:play-services-gcm:11.8.0'
resolutionStrategy.force 'com.google.android.gms:play-services-analytics:11.8.0'
resolutionStrategy.force 'com.google.android.gms:play-services-location:11.8.0'
resolutionStrategy.force 'com.facebook.android:facebook-android-sdk:4.18.0'
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "my.android.mobileapp"
minSdkVersion 16
targetSdkVersion 25
versionCode 24
versionName "0.0.24"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [
'onesignal_app_id': "xxxxx-xxxxx-xxx-xxxxx",
'onesignal_google_project_number': "12345676789"
]
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile project(':react-native-fabric')
compile project(':react-native-spinkit')
compile project(':react-native-push-notification')
compile project(':react-native-google-analytics-bridge')
compile project(':react-native-svg')
compile project(':react-native-onesignal')
compile fileTree(dir: "libs", include: ["*.jar"])
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-fabric')
compile('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
transitive = true;
}
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
changelog:
// https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'io.fabric'
plugins {
id 'com.onesignal.androidsdk.onesignal-gradle-plugin' version '0.10.2' apply false
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
我试过了:
这些都没有奏效。
我应该在哪里添加plugin
声明?
另外,my_app/android/app/build.gradle
是将plugin
语句添加到?
答案 0 :(得分:0)
如果您使用plugins
脚本块,则需要将其作为第一个块放在build.gradle
文件中。
此规则的唯一例外是其他plugins
或buildScript
块。
然后放在顶部:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
plugins {
id 'com.onesignal.androidsdk.onesignal-gradle-plugin' version '0.10.2' apply false
}
apply plugin: 'io.fabric'
apply plugin: 'com.android.application'
//...