反应本地gradle配置

时间:2019-03-19 23:44:32

标签: react-native configuration android-gradle

我对本地人反应很新。

我不了解一件事:实际上,当我通过Android Studio启动项目时,构建窗口中总是存在错误。但是我的应用程序出现了,我可以在Vs Code中对其进行调试。

今天,什么都没有。我没有安装任何扩展程序,只是在UI上工作。

但是我确定gradle的配置错误,并且在网络上找不到任何解决方案。

因此,我在android studio中将与graddle相关的不同文件的内容放在下面:

build.gradle:主项目:

// Top-level build file where you can add   configuration options common to all sub-projects/modules.

buildscript {
ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 23
    compileSdkVersion = 28
    targetSdkVersion = 28
    supportLibVersion = "28.0.0"
}
repositories {
    google()
    jcenter()
mavenCentral()
    }
}
dependencies {
    classpath  'com.android.tools.build:gradle:3.3.1'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files

    implemantation project('mapbox-react-native-mapbox-gl')

}

allprojects {
repositories {
    mavenLocal()
    google()
    jcenter()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
}
}

build.gradle:模块@mapbox ...

apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion '28.0.3'

defaultConfig {
    minSdkVersion 23
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles  getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

// React Native
compileOnly "com.facebook.react:react-native:+"

// Mapbox SDK
compile 'com.mapbox.mapboxsdk:mapbox-android-services:2.2.9'

compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.4.1@aar') {
    transitive=true
}

// Mapbox plugins
compile 'com.mapbox.mapboxsdk:mapbox- android-plugin-localization:0.1.0'
compile 'com.mapbox.mapboxsdk:mapbox- android-plugin-locationlayer:0.3.0'
}

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"

/**
 * Set this to true to create two  separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion  rootProject.ext.compileSdkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
    applicationId "com.myapp"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}
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, "arm64-v8a": 3, "x86_64": 4]
        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 {
implementation project(':@mapbox_react-native-mapbox-gl')
implementation project(':react-native-calendar-events')
implementation project(':react-native-gesture-handler')
implementation fileTree(dir: "libs",   include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder    libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}



apply from: "../../node_modules/react-native/react.gradle"

build.gradle:模块日历:

apply plugin: 'com.android.library'

android {
compileSdkVersion 27
buildToolsVersion '28.0.3'

defaultConfig {
    minSdkVersion 23
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"

}
lintOptions {
   warning 'InvalidPackage'
}
}

dependencies {
api 'com.facebook.react:react-native:+'
}

build.gradle:模块手势

apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
compileSdkVersion safeExtGet("compileSdkVersion", 28)
buildToolsVersion safeExtGet("buildToolsVersion", '25.0.2')

defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 23)
    targetSdkVersion  safeExtGet('targetSdkVersion', 25)
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
 }

// Include "lib/" as sources, unfortunetely react-native link can't handle
// setting up alternative gradle modules. We still have "lib" defined as a
// standalone gradle module just to be used in AndroidNativeExample
sourceSets {
    main.java.srcDirs += 'lib/src/main/java'
}
}

dependencies {
//noinspection GradleDynamicVersion
compileOnly 'com.facebook.react:react-native:+'
 }

settings.gradle:

rootProject.name = 'MyApp'
include ':@mapbox_react-native-mapbox-gl'
project(':@mapbox_react-native-mapbox-gl').projectDir = new  File(rootProject.projectDir, '../node_modules/@mapbox/react-native-mapbox-gl/android/rctmgl')

include ':react-native-calendar-events'
project(':react-native-calendar-events').projectDir = new    File(rootProject.projectDir, '../node_modules/react-native-calendar-events/android')
 include ':react-native-gesture-handler'
 project(':react-native-gesture-handler').projectDir = new   File(rootProject.projectDir, '../node_modules  /react-native-gesture-handler/android')

include ':app'

MainActivity:

package com.myapp;
import com.facebook.react.ReactActivity;
import   com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import   com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends  ReactActivity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() {
    return "myApp";
}

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
        @Override
        protected ReactRootView createRootView() {
            return new RNGestureHandlerEnabledRootView(MainActivity.this);
        }
    };
}
}

MainApplication

package com.myapp;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.mapbox.rctmgl.RCTMGLPackage;
import  com.calendarevents.CalendarEventsPackage;
import  com.swmansion.gesturehandler.react.RNGestureH andlerPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends  Application implements ReactApplication {

 private final ReactNativeHost  mReactNativeHost = new ReactNativeHost(this)   {
@Override
public boolean getUseDeveloperSupport() {
  return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage>  getPackages() {
  return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
        new RCTMGLPackage(),
        new CalendarEventsPackage(),
        new RNGestureHandlerPackage()
  );
}

@Override
protected String getJSMainModuleName() {
  return "index";
}
};

@Override
public ReactNativeHost getReactNativeHost()   {
return mReactNativeHost;
}

@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage  */ false);
}
}

最后,调试窗口中显示的错误是:

“在类型org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler类型的对象上找不到参数[com.android.tools.build:gradle:3.3.1]的方法classpath()。” < / p>

0 个答案:

没有答案