android React native v0.71.8 react-native-vector-icons你看不到的图标

kqlmhetl  于 2023-06-20  发布在  Android
关注(0)|答案(1)|浏览(163)

我使用的是react native版本v0.71.8
我安装了react-native-vector-icons库,但图标不显示。
链接似乎在最新版本的react native中不再起作用。
所以我按照指示,但它不编译了,我得到下面的错误.
我按照说明,将字符串apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"添加到android/app/build.gradle文件中
如文件第4行所示:

  1. apply plugin: "com.android.application"
  2. apply plugin: "com.facebook.react"
  3. import com.android.build.OutputFile
  4. apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
  5. /**
  6. * This is the configuration block to customize your React Native Android app.
  7. * By default you don't need to apply any configuration, just uncomment the lines you need.
  8. */
  9. react {
  10. /* Folders */
  11. // The root of your project, i.e. where "package.json" lives. Default is '..'
  12. // root = file("../")
  13. // The folder where the react-native NPM package is. Default is ../node_modules/react-native
  14. // reactNativeDir = file("../node_modules/react-native")
  15. // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
  16. // codegenDir = file("../node_modules/react-native-codegen")
  17. // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
  18. // cliFile = file("../node_modules/react-native/cli.js")
  19. /* Variants */
  20. // The list of variants to that are debuggable. For those we're going to
  21. // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
  22. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
  23. // debuggableVariants = ["liteDebug", "prodDebug"]
  24. /* Bundling */
  25. // A list containing the node command and its flags. Default is just 'node'.
  26. // nodeExecutableAndArgs = ["node"]
  27. //
  28. // The command to run when bundling. By default is 'bundle'
  29. // bundleCommand = "ram-bundle"
  30. //
  31. // The path to the CLI configuration file. Default is empty.
  32. // bundleConfig = file(../rn-cli.config.js)
  33. //
  34. // The name of the generated asset file containing your JS bundle
  35. // bundleAssetName = "MyApplication.android.bundle"
  36. //
  37. // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
  38. // entryFile = file("../js/MyApplication.android.js")
  39. //
  40. // A list of extra flags to pass to the 'bundle' commands.
  41. // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
  42. // extraPackagerArgs = []
  43. /* Hermes Commands */
  44. // The hermes compiler command to run. By default it is 'hermesc'
  45. // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
  46. //
  47. // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
  48. // hermesFlags = ["-O", "-output-source-map"]
  49. }
  50. /**
  51. * Set this to true to create four separate APKs instead of one,
  52. * one for each native architecture. This is useful if you don't
  53. * use App Bundles (https://developer.android.com/guide/app-bundle/)
  54. * and want to have separate APKs to upload to the Play Store.
  55. */
  56. def enableSeparateBuildPerCPUArchitecture = false
  57. /**
  58. * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
  59. */
  60. def enableProguardInReleaseBuilds = false
  61. /**
  62. * The preferred build flavor of JavaScriptCore (JSC)
  63. *
  64. * For example, to use the international variant, you can use:
  65. * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
  66. *
  67. * The international variant includes ICU i18n library and necessary data
  68. * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
  69. * give correct results when using with locales other than en-US. Note that
  70. * this variant is about 6MiB larger per architecture than default.
  71. */
  72. def jscFlavor = 'org.webkit:android-jsc:+'
  73. /**
  74. * Private function to get the list of Native Architectures you want to build.
  75. * This reads the value from reactNativeArchitectures in your gradle.properties
  76. * file and works together with the --active-arch-only flag of react-native run-android.
  77. */
  78. def reactNativeArchitectures() {
  79. def value = project.getProperties().get("reactNativeArchitectures")
  80. return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
  81. }
  82. android {
  83. ndkVersion rootProject.ext.ndkVersion
  84. compileSdkVersion rootProject.ext.compileSdkVersion
  85. namespace "com.fuelapk"
  86. defaultConfig {
  87. applicationId "com.fuelapk"
  88. minSdkVersion rootProject.ext.minSdkVersion
  89. targetSdkVersion rootProject.ext.targetSdkVersion
  90. versionCode 1
  91. versionName "1.0"
  92. }
  93. splits {
  94. abi {
  95. reset()
  96. enable enableSeparateBuildPerCPUArchitecture
  97. universalApk false // If true, also generate a universal APK
  98. include (*reactNativeArchitectures())
  99. }
  100. }
  101. signingConfigs {
  102. debug {
  103. storeFile file('debug.keystore')
  104. storePassword 'android'
  105. keyAlias 'androiddebugkey'
  106. keyPassword 'android'
  107. }
  108. }
  109. buildTypes {
  110. debug {
  111. signingConfig signingConfigs.debug
  112. }
  113. release {
  114. // Caution! In production, you need to generate your own keystore file.
  115. // see https://reactnative.dev/docs/signed-apk-android.
  116. signingConfig signingConfigs.debug
  117. minifyEnabled enableProguardInReleaseBuilds
  118. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  119. }
  120. }
  121. // applicationVariants are e.g. debug, release
  122. applicationVariants.all { variant ->
  123. variant.outputs.each { output ->
  124. // For each separate APK per architecture, set a unique version code as described here:
  125. // https://developer.android.com/studio/build/configure-apk-splits.html
  126. // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
  127. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
  128. def abi = output.getFilter(OutputFile.ABI)
  129. if (abi != null) { // null for the universal-debug, universal-release variants
  130. output.versionCodeOverride =
  131. defaultConfig.versionCode * 1000 + versionCodes.get(abi)
  132. }
  133. }
  134. }
  135. }
  136. dependencies {
  137. // The version of react-native is set by the React Native Gradle Plugin
  138. implementation("com.facebook.react:react-android")
  139. implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
  140. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
  141. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  142. exclude group:'com.squareup.okhttp3', module:'okhttp'
  143. }
  144. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
  145. if (hermesEnabled.toBoolean()) {
  146. implementation("com.facebook.react:hermes-android")
  147. } else {
  148. implementation jscFlavor
  149. }
  150. }
  151. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

我得到以下错误:

  1. * What went wrong:
  2. A problem occurred configuring project ':app'.
  3. > Could not open cp_proj generic class cache for build file
  4. '/Users/nameUser/Desktop/project/android/app/build.gradle'
  5. (/Users/nameUser/.gradle/caches/7.5.1/scripts/df0ag1ifx5mu2eejb9lni6xez).
  6. > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_'
  7. Unsupported class file major version 64

java:java -版本

  1. openjdk version "20.0.1" 2023-04-18
  2. OpenJDK Runtime Environment (build 20.0.1+9-29)
  3. OpenJDK 64-Bit Server VM (build 20.0.1+9-29, mixed mode, sharing)

你能帮帮我吗,我做错了什么?

q8l4jmvw

q8l4jmvw1#

这是一个Gradle和Java版本组合的问题。
我让它与Gradle 7.5.1和Java 16.0.2一起工作
您可以通过更改JAVA_HOME路径来更改Java版本,请确保您首先下载版本,然后:

  1. export JAVA_HOME=`/usr/libexec/java_home -v 16`

Gradle版本可以在项目> <root>/android/gradle/wrapper/gradle-wrapper.properties上更改

  1. distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip

相关问题