آموزش جاوااسکریپت › انجمن ها › react native › مشکل در استفاده از react-navigation
برچسب ها: navigation, react-navigation
- این موضوع 14 پاسخ، 5 کاربر را دارد و آخرین بار در 4 سال، 2 ماه پیش بدست مهدی حسن زاده بهروزرسانی شده است.
-
نویسندهنوشتهها
-
armanebartarمشارکت کننده
با سلام
من تو استفاده از react-navigation خیلی به مشکل خوردم و الان که این موارد رو تونستم رفع کنم خواستم این تاپیک رو ایجاد کنم شاید بعضی از دوستان هم به این مشکلات برخورد کنن و با این نکات مشکلشون رفع بشه.
ا – نصب پکیج : مراحل نصب مطابق آموزشی هست که استاد محترم تو این لینک قرار دادن (https://reactapp.ir/getting-started-with-react-navigation/) ولی اگه به مشکل خوردین مرحله سوم رو انجام ندین و بعد از اینکه مرحله پنجم رو اجرا کردین دستور زیر رو هم اجرا کنید
react-native link react-native-gesture-handler۲ – از پوشه android فایل settings.gradle رو با ویرایشگر متن باز کنید و تمام بک اسلش ها (\) و با اسلش (/) جایگزین کنید.
۳ – از مسیر android/app فایل build.gradle رو با ویرایشگر متن باز کنید و بدنبال عبارت compileSdkVersion بگردید و عدد جلوی اونو به “23.0” تغییر بدین.
حال میتونید دستور react-native run-android رو اجرا کنید.
امیدوارم براتون مفید واقع بشه.
حساممیهمانآقا دمت گرم .کل نت فارسی و انگلیسی رو زیر و رو کردم ولی مشکلم حل نشد با این دو تا کاری که گفتی درست شد
npbمشارکت کنندهسلام ممنون بابت تایپک خوبی که گذاشتین
منم تمام مراحل رو انجام دادم ولی بازم که react-native run-android برای اجراش می زنم این خطا ظاهر میشه
BUILD FAILED in 2s
19 actionable tasks: 1 executed, 18 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.htmlCommand failed: gradlew.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:621:11)
at Object.execFileSync (child_process.js:639:13)
at runOnAllDevices (D:\nativeproject\myproject\pr2\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
at buildAndRun (D:\nativeproject\myproject\pr2\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
at isPackagerRunning.then.result (D:\nativeproject\myproject\pr2\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
at process.internalTickCallback (internal/process/next_tick.js:77:7)لطفا راهنماییم کنین
armanebartarمشارکت کنندهاولین خطای قرمزی که نشون میده رو اینجا قرار بدین یا یک اسکرین شات بگیرین و تو سایتهای آپلود عکس ذخیره کنید و لینکش رو اینجا بزارید.
npbمشارکت کنندهسلام
این خطا هست
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)…> Configure project :app
WARNING: The specified Android SDK Build Tools version (28.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove “buildToolsVersion ‘28.0.2’” from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Observed package id ‘build-tools;26.0.0-rc2’ in inconsistent location ‘D:\Best_Edu_ForBuildProgramer\ReactNative\software\SDK\SDK\build-tools\26.0.0-preview’ (Expected ‘D:\Best_Edu_ForBuildProgramer\ReactNative\software\SDK\SDK\build-tools\26.0.0-rc2’)
Observed package id ‘build-tools;26.0.0-rc2’ in inconsistent location ‘D:\Best_Edu_ForBuildProgramer\ReactNative\software\SDK\SDK\build-tools\26.0.0-preview’ (Expected ‘D:\Best_Edu_ForBuildProgramer\ReactNative\software\SDK\SDK\build-tools\26.0.0-rc2’)FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ‘:app’.
> Failed to find target with hash string ‘23.0’ in: D:\Best_Edu_ForBuildProgramer\ReactNative\software\SDK\SDK* Try:
Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output. Run with –scan to get full insights.* Get more help at https://help.gradle.org
BUILD FAILED in 5s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.htmlCommand failed: gradlew.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:621:11)
at Object.execFileSync (child_process.js:639:13)
at runOnAllDevices (D:\nativeproject\reactnavigation\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
at buildAndRun (D:\nativeproject\reactnavigation\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
at isPackagerRunning.then.result (D:\nativeproject\reactnavigation\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
at process.internalTickCallback (internal/process/next_tick.js:77:7)این تنظیم اخری هم داخل فایل android/build.gradle گذاشتم درسته؟
buildscript {
ext {
buildToolsVersion = “28.0.2”
minSdkVersion = 16
compileSdkVersion = “23.0”
targetSdkVersion = 27
supportLibVersion = “28.0.0”
}
repositories {
google()
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:3.2.1’// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}armanebartarمشارکت کنندهالبته من خودم تو reactNative خیلی تازه کارم و در اون حدی نیستم که بخام راهنمایی کنم ولی طبق این اروری که داده فکر میکنم باید از مسیر android فایل build.gradle رو با ویرایشگر باز کنید و مقدار buildToolsVersion رو به 28.0.3 تغییر بدین.
مهدی حسن زادهمدیرکلببینید شما فایل build.gradle موجود در پوشه android/app رو باز کنید در این فایل باید مقادیر sdk و targetsdk و buildtools رو با توجه به sdk تنظیم کنید.اگر شما buildTools نسخه 23.0.1 رو به طور مثال در sdk دارید و نسخه ای بالاتر رو ندارید باید در این فایل تنظیمات رو بر اساس فایل های موجود در sdk تنظیم کنید.همچنین هر کتابخونه ای که نصب میکنید باید به پوشه node_module و پوشه کتابخونه مورد نظر برید و تنظیمات رو برای فایل build کتابخونه ها هم انجام بدید
مهدی حسن زادهمدیرکلببینید شما فایل build.gradle موجود در پوشه android/app رو باز کنید در این فایل باید مقادیر sdk و targetsdk و buildtools رو با توجه به sdk تنظیم کنید.اگر شما buildTools نسخه 23.0.1 رو به طور مثال در sdk دارید و نسخه ای بالاتر رو ندارید باید در این فایل تنظیمات رو بر اساس فایل های موجود در sdk تنظیم کنید.همچنین هر کتابخونه ای که نصب میکنید باید به پوشه node_module و پوشه کتابخونه مورد نظر برید و تنظیمات رو برای فایل build کتابخونه ها هم انجام بدید
npbمشارکت کنندهبا سلام
همه موارد رو از اول دوباره نصب کردم و انجام دادم و این بار مشکل حل شد
ممنونم برای وقتی که گذاشتین و راهنمایی کردین هم شما آقای مهدی هم آقای armanebartarسپاسگزارم
pejmanradمشارکت کنندهتوی پوشه android فایل settings.gradle فقط همین دو خط کد هست
rootProject.name = ‘projectName’
include ‘:app’وتوی فایل android/app فایل build.gradle کد زیر هست ک اصلا ورژن نداره:
apply plugin: “com.android.application”import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically callreact-native bundle
with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
*apply from: "../../node_modules/react-native/react.gradle"
line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: “index.android.bundle”,
*
* // the entry file for bundle generation
* entryFile: “index.android.js”,
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // ‘bundleIn${productFlavor}${buildType}’
* // ‘bundleIn${buildType}’
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // ‘devDisabledIn${productFlavor}${buildType}’
* // ‘devDisabledIn${buildType}’
*
* // the root of your project, i.e. where “package.json” lives
* root: “../../”,
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: “$buildDir/intermediates/assets/debug”,
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: “$buildDir/intermediates/assets/release”,
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require(‘./image.png’)), in debug mode
* resourcesDirDebug: “$buildDir/intermediates/res/merged/debug”,
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require(‘./image.png’)), in release mode
* resourcesDirRelease: “$buildDir/intermediates/res/merged/release”,
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don’t look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: [“android/**”, “ios/**”],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: [“node”],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/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 = falseandroid {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersiondefaultConfig {
applicationId “com.pejmannav”
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”
}
}
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]
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 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’
}حالا باید چیکار کنم؟
مهدیمیهمانداخل پوشه اندروید یک پوشه به اسم app دارید و داخل اون پوشه فایلbuild.gradle هست،اونجا میتونید نسخه های مختلف رو ببینید
pejmanradمشارکت کنندههمه این کارا رو کردم ولی بازم اررو زیر رو میده
null is not an object (evaluting ‘RNGestureHandlerModule.Direction’)مهدی حسن زادهمدیرکللینک کردن کتابخانه مشکل داره.ب صورت دستی این کار رو انجام بدید
pejmanradمشارکت کنندهباید چطوری لینک کنم
میشه راهنمایی کنید لطفا یه هفتس اعصاب نزاشته واسم
هرجام میگردم چیزی پیدا نمیکنممهدی حسن زادهمدیرکلاز طریق لینک زیر میتونید به صورت دستی عملیات لینک رو انجام بدید
https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html -
نویسندهنوشتهها