首页 \ 问答 \ 无法从Android Studio构建react-native,Build失败(cannot build react-native from Android Studio, Build failed)

无法从Android Studio构建react-native,Build失败(cannot build react-native from Android Studio, Build failed)

安装react-native-fcm后,构建不成功。 我不太确定要更改哪些内容以及我用于Google服务的版本。

我的项目grandle文件如下所示:

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

buildscript {
  repositories {
    jcenter()
    google()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.google.gms:google-services:3.1.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    mavenLocal()
    jcenter()
    maven {
      // Point to local maven repository
      url "$rootDir/../.expo-source/android/maven"
    }
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

和我的项目/应用程序/ grandle看起来像:

    apply plugin: 'com.android.application'

android {
  compileSdkVersion 26
  buildToolsVersion '26.0.2'

  defaultConfig {
    applicationId "fi.rogerstudio.possis"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 2
    versionName "1.0.2"
    multiDexEnabled true
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'fi.rogerstudio.possis'
    ]
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  dexOptions {
    javaMaxHeapSize "8g"
  }
  lintOptions {
    abortOnError false
  }
}

task exponentPrebuildStep(type: Exec) {
  workingDir '../../'

  if (System.getProperty('os.name').toLowerCase().contains('windows')) {
    commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat'
  } else {
    commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh'
  }
}
preBuild.dependsOn exponentPrebuildStep

repositories{
  flatDir{
    dirs "../../node_modules/react-native-background-geolocation/android/libs"
  }
  mavenLocal()
  maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile(project(':react-native-firebase')) {
        transitive = false
    }
    compile project(':react-native-vector-icons')
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:multidex:1.0.2'

  compile 'com.google.android.gms:play-services:11.6.2'
  compile 'com.google.android.gms:play-services-location:11.6.2'
  compile 'com.google.android.gms:play-services-places:11.6.2'
  compile 'com.google.android.gms:play-services-maps:11.6.2'
  compile 'com.google.android.gms:play-services-ads:11.6.2'

  compile('host.exp.exponent:expoview:22.0.0@aar') {
    exclude group: 'com.facebook.android', module: 'facebook-android-sdk'
    exclude group: 'com.facebook.android', module: 'audience-network-sdk'
    exclude group: 'io.nlopez.smartlocation', module: 'library'
    transitive = true
  }

  compile ('com.facebook.android:facebook-android-sdk:4.+')
  compile('com.facebook.android:audience-network-sdk:4.+') {
    exclude module: 'play-services-ads'
  }
  compile('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  compile(project(':react-native-background-geolocation')) {
    exclude group: 'com.google.android.gms', module: 'play-services-location'
  }
  compile(name: 'tslocationmanager', ext: 'aar') {
    exclude group: 'com.google.android.gms'
  }
  compile "com.google.firebase:firebase-messaging:11.6.2"


}

apply plugin: 'com.google.gms.google-services'

我得到的错误是:

Error:Execution failed for task 
app:processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.6.2.

我找不到解决这个问题的方法


After installing react-native-fcm , the build does not succeed. I am not quite sure what to change and what version do I use for google services.

My project grandle file looks as below:

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

buildscript {
  repositories {
    jcenter()
    google()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.google.gms:google-services:3.1.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    mavenLocal()
    jcenter()
    maven {
      // Point to local maven repository
      url "$rootDir/../.expo-source/android/maven"
    }
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

and my project/app/grandle looks like:

    apply plugin: 'com.android.application'

android {
  compileSdkVersion 26
  buildToolsVersion '26.0.2'

  defaultConfig {
    applicationId "fi.rogerstudio.possis"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 2
    versionName "1.0.2"
    multiDexEnabled true
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'fi.rogerstudio.possis'
    ]
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  dexOptions {
    javaMaxHeapSize "8g"
  }
  lintOptions {
    abortOnError false
  }
}

task exponentPrebuildStep(type: Exec) {
  workingDir '../../'

  if (System.getProperty('os.name').toLowerCase().contains('windows')) {
    commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat'
  } else {
    commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh'
  }
}
preBuild.dependsOn exponentPrebuildStep

repositories{
  flatDir{
    dirs "../../node_modules/react-native-background-geolocation/android/libs"
  }
  mavenLocal()
  maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile(project(':react-native-firebase')) {
        transitive = false
    }
    compile project(':react-native-vector-icons')
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:multidex:1.0.2'

  compile 'com.google.android.gms:play-services:11.6.2'
  compile 'com.google.android.gms:play-services-location:11.6.2'
  compile 'com.google.android.gms:play-services-places:11.6.2'
  compile 'com.google.android.gms:play-services-maps:11.6.2'
  compile 'com.google.android.gms:play-services-ads:11.6.2'

  compile('host.exp.exponent:expoview:22.0.0@aar') {
    exclude group: 'com.facebook.android', module: 'facebook-android-sdk'
    exclude group: 'com.facebook.android', module: 'audience-network-sdk'
    exclude group: 'io.nlopez.smartlocation', module: 'library'
    transitive = true
  }

  compile ('com.facebook.android:facebook-android-sdk:4.+')
  compile('com.facebook.android:audience-network-sdk:4.+') {
    exclude module: 'play-services-ads'
  }
  compile('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  compile(project(':react-native-background-geolocation')) {
    exclude group: 'com.google.android.gms', module: 'play-services-location'
  }
  compile(name: 'tslocationmanager', ext: 'aar') {
    exclude group: 'com.google.android.gms'
  }
  compile "com.google.firebase:firebase-messaging:11.6.2"


}

apply plugin: 'com.google.gms.google-services'

The error I am getting is:

Error:Execution failed for task 
app:processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.6.2.

I cannot find any way of how do I solve this issue...


原文:https://stackoverflow.com/questions/48406647
更新时间:2022-04-28 22:04

最满意答案

在您的onClick方法的主Activity中执行如下操作:

MyFragment myFragment = (MyFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if(myFragment != null && myFragment.isAdded(){
    myFragment.myRecyclerView.notifyItemRemoved();
}

简要解释:像这样,您正在您的片段容器中检索片段的实例,空检查总是一种很好的做法,以确保您不会在某个NPE中最终出现,然后从片段实例访问您的回收器视图。


In your main Activity in your onClick method do something like:

MyFragment myFragment = (MyFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if(myFragment != null && myFragment.isAdded(){
    myFragment.myRecyclerView.notifyItemRemoved();
}

Brief explanation: Like this you are retrieving the instance of your fragment inside your fragment container, a null check is always a good practice to insure you won't end up in some NPE, and then access your recycler view from your fragment instance.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)