android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 19
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
repositories {
jcenter()
google()
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support' && requested.name != 'multidex') {
details.useVersion "${rootProject.ext.supportLibVersion}"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
settings.gradle
rootProject.name = 'XProj1'
include ':app'
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/lib/android/app/')
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
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
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.xproj1"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57"
versionCode 1
versionName "1.0"
multiDexEnabled true
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
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
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support' && requested.name != 'multidex') {
details.useVersion "${rootProject.ext.supportLibVersion}"
}
}
}
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
implementation project(':react-native-navigation')
implementation 'com.android.support:design:25.4.0'
implementation "com.android.support:multidex:1.0.3"
}
// 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'
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xproj1">
<application
android:name="android.support.multidex.MultiDexApplication" >
</application>
</manifest>
MainActivity.java
package com.xproj1;
//import com.facebook.react.ReactActivity;
import com.reactnativenavigation.NavigationActivity;
public class MainActivity extends NavigationActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
// #Override
// protected String getMainComponentName() {
// return "XProj1";
// }
}
MainApplication.java
package com.xproj1;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends NavigationApplication{
#Override
protected ReactGateway createReactGateway() {
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
#Override
protected String getJSMainModuleName() {
return "index";
}
};
return new ReactGateway(this, isDebug(), host);
}
#Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
protected List<ReactPackage> getPackages() {
// Add additional packages you require here
// No need to add RnnPackage and MainReactPackage
return Arrays.<ReactPackage>asList(
// eg. new VectorIconsPackage()
);
}
#Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
}
Wix 'React-Native-Navigation' V2 is not supporting for RN 57. I have tried all the ways from this PR PR for RN 57 Support. Still Facing Issues. Can anyone write a quick Medium Post on how to Integrate Navigation with RN 57 support.
Need both maven for react-native and jitpack android/build.gradle
allprojects {
repositories {
mavenLocal()
mavenCentral()
google()
jcenter()
maven
{ url "$rootDir/../node_modules/react-native/android"}
maven
{ url 'https://jitpack.io' }
}
}
Ignore other RNN flavors
in end of android/build.gradle
add below mention code.
subprojects { subproject ->
afterEvaluate {
if ((subproject.plugins.hasPlugin('android') ||
subproject.plugins.hasPlugin('android-library'))) {
android {
variantFilter { variant ->
def names = variant.flavors*.name
if (names.contains("reactNative51") ||
names.contains("reactNative55")) {
setIgnore(true)
}
}
}
}
}
}
Just do a yarn add https://github.com/leonardoballand/react-native-navigation-rn57.git and you're good to go, just follow the Wix library instructions.
I was able to run react-native-navigation#^2.1.2 along with react-native#^0.57.5 & react#16.6.1.
The only difference that I could spot is that I added the RNN flavors configuration even though it's not highlighted as a mandatory step in the official documentation.
app/build.gradle
subprojects { subproject ->
afterEvaluate {
if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
variantFilter { variant ->
def names = variant.flavors*.name
if (names.contains("reactNative51") || names.contains("reactNative55") || names.contains("reactNative56")) {
setIgnore(true)
}
}
}
}
}
}
Related
For my college project I want to use data from Firestore, and then use MVVM pattern to display the items on the Lazy Column.
Here is the code of the screen of where I want the values of viewmodel to be displayed:
fun HomeScreen (navController: NavController, viewModel: ArticleViewModel = hiltViewModel()){
var expanded = remember { mutableStateOf(false) }
val articleResponse = viewModel.articleState.value
Scaffold() {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.background(Color.White)
) {
items(items = articleResponse.data) {
ArticleList(model = it) { model ->
Log.d("TAG", "Clicked on $model")
navController.navigate(route = NavScreens.DetailScreen.name +"/$model")
}
}
}
}
}
Here is the field of where exactly I get the error that is I mentioned in the title:
here
Previously I used an array to display the item in the LazyColumn and it worked normally.
Perhaps, the problem lies in the ViewModel? Here is the ViewModel that I'm using:
#HiltViewModel
class ArticleViewModel #Inject constructor(
private val useCases: UseCases
):ViewModel() {
private val _articleState = mutableStateOf<Response<List<Article>>>(Response.Loading)
val articleState: State<Response<List<Article>>> = _articleState
init {
getArticles()
}
private fun getArticles() {
viewModelScope.launch {
useCases.getArticle().collect { response ->
_articleState.value = response
}
}
}
}
When I tried searching for the solution, I've read that the problem could be with the dependencies/plugins, I have tried changing couple of the dependencies but the issue still persists. I've heard that some of the plugins doesn't work with others since I'm new to jetpack compose it is harder for me to identify the issues within the dependencies.
Here is my Gradle files:
buildscript {
ext {
compose_version = '1.0.1'
hilt_version = "2.40.5"
gradle_version = "7.2.0"
kotlin_version = "1.6.20"
coroutines_version = "1.6.1"
google_services_version = "4.3.10"
hilt_version = "2.40.5"
core_version = "1.7.0"
appcompat_version = "1.4.1"
live_data_version = "2.4.1"
activity_compose_version = "1.4.0"
material_version = "1.6.0"
hilt_navigation_compose_version = "1.0.0"
firebase_bom_version = "30.0.0"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.4'
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:google-services:$google_services_version"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.5.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
id 'dagger.hilt.android.plugin'
id 'kotlin-kapt'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.flow"
minSdk 28
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation "androidx.compose.compiler:compiler:1.0.0-beta08"
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-alpha02'
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.core:core-splashscreen:1.0.0-beta02"
implementation "androidx.navigation:navigation-compose:2.4.0-alpha10"
implementation("io.coil-kt:coil-compose:2.1.0")
implementation "com.google.firebase:firebase-firestore:22.0.1"
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation platform("com.google.firebase:firebase-bom:$firebase_bom_version")
implementation "com.google.firebase:firebase-firestore-ktx"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation_compose_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutines_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$live_data_version"
}
I would be grateful if you are able to assist me on finding the solution.
The problem is that articleState.value is Response not List. You can do something like that:
val articleResponse = viewModel.articleState.value
when (articleResponse) {
Response.Loading -> <LoadingComponenet />
Response.Error -> <ErrorComponent />
Response.Success -> Scaffold() {
.............
}
}
I try add sqldelight to my Kotlin Multiplatform App, but AndroidSqliteDriver unresolved reference. I dont understand why.
I clear cache and regenerate all, but it dont work too.
AndroidSqliteDriver:
package com.rompos.deactivator
import com.squareup.sqldelight.android.AndroidSqliteDriver
import android.content.Context
lateinit var appContext: Context
actual fun createDB() : Server {
val driver = AndroidSqliteDriver(Server.Schema, appContext, "Server.db")
return Server(driver)
}
build.gradle(common):
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.squareup.sqldelight")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
// Common Main
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("io.ktor:ktor-client-core:1.3.2")
implementation("com.squareup.sqldelight:runtime:1.4.0")
}
// Android Main
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("com.squareup.sqldelight:android-driver:1.4.0") {
exclude(group = "com.squareup.sqldelight", module = "runtime-jdk")
}
}
// iOS Main
sourceSets["iosMain"].dependencies {
implementation("com.squareup.sqldelight:native-driver:1.4.0")
}
}
build.gradle(android):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'
apply plugin: 'com.squareup.sqldelight'
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.rompos.deactivator"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/*.kotlin_module'
}
buildFeatures {
dataBinding true
}
}
dependencies {
implementation project(':SharedCode')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.3.1"
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "com.google.android.material:material:1.2.0"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation
"androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-
android:1.3.7"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-
runtime:0.20.0"
implementation "io.ktor:ktor-client-android:1.3.2"
implementation "com.squareup.sqldelight:android-
driver:$sqldelight_version"
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-
core:3.2.0'
}
build.gradle(project):
buildscript {
ext {
ext.kotlin_version = '1.3.72'
sqldelight_version = "1.4.0"
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-
plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-
serialization:$kotlin_version"
classpath "com.squareup.sqldelight:gradle-
plugin:$sqldelight_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I use:
gradle: 6.1.1
gradle plugin: 4.0.1
kotlin: 1.3.72
upd: Add code
you only have a jvm target jvm("android") and not an android target. you need an android library or application target to use the android library.
EDIT: To add an android target:
//build.gradle(common)
plugins {
...
// assuming your building a library. use application otherwise
id("com.android.library")
id("kotlin-android")
}
...
android {
// fill in your library or app info here
}
kotlin {
android { // creates androidMain/Test source sets
// ex: publishLibraryVariants("release", "debug")
}
ios() { ... }
val commonMain by getting { ... }
val androidMain by getting { ... }
...
}
Make sure you're using at least Android Studio 4.1.
You should only need to include the SQLDelight plugin in your common build.gradle.
build.gradle
...
apply plugin: "com.squareup.sqldelight" in the common build.gradle
...
sourceSets {
commonMain.dependencies {
...
// SQL Delight
implementation "com.squareup.sqldelight:runtime:${Versions.sqlDelight}"
implementation "com.squareup.sqldelight:coroutines-extensions:${Versions.sqlDelight}"
}
androidMain.dependencies {
...
// SQL Delight
implementation "com.squareup.sqldelight:android-driver:${Versions.sqlDelight}"
implementation "com.squareup.sqldelight:coroutines-extensions-jvm:${Versions.sqlDelight}"
}
iOSMain.dependencies {
...
// SQL Delight
implementation "com.squareup.sqldelight:ios-driver:${Versions.sqlDelight}"
}
}
i should call function from native-android to react-native, so i set bridge. before set bridge, apk run & virtual run worked well.
but after set, vertual run work too, but apk run is not work.
i can't find the reason.
KeyStoreApi.java
package com.tovidapp;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.uimanager.IllegalViewOperationException;
public class KeyStoreApi extends ReactContextBaseJavaModule {
public KeyStoreApi(ReactApplicationContext reactContext){
super(reactContext);
}
#Override
public String getName(){
return "KeyStoreApi";
}
#ReactMethod
public void sayHi(Callback errCallBack, Callback successCallBack){
try{
System.out.println("Hello, i am from java");
successCallBack.invoke("Callback: Greeting from java");;
}catch (IllegalViewOperationException e){
errCallBack.invoke(e.getMessage());
}
}
}
KeyStoreApiPackage.java
package com.tovidapp;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class KeyStoreApiPackage implements ReactPackage {
#Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext){
return Collections.emptyList();
}
#Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext){
List<NativeModule> modules = new ArrayList<>();
modules.add(new KeyStoreApi(reactContext));
return modules;
}
}
build.grade
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
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.tovidapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
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"
signingConfig signingConfigs.release
}
}
// 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(':react-native-youtube')
implementation project(':react-native-vector-icons')
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'
}
call.js
import React, {Component} from 'react';
import {View, Text, NativeModules, TouchableOpacity,} from 'react-native';
const keyStoreApi = NativeModules.KeyStoreApi;
class Account extends Component {
async sayHiFromJava() {
keyStoreApi.sayHi(err => {
alert(err);
}, msg => {
alert(msg);
})
}
render() {
return (
<View>
<TouchableOpacity onPress={this.sayHiFromJava}>
<Text>TEST</Text>
</TouchableOpacity>
</View>
);
}
}
export default Account;
script in package.json
"android-apk": "react-native run-android --variant=release",
"android-virtual": "react-native run-android",
"android-build": "rm android/app/build/outputs/apk/release/app-release.apk & cd android && ./gradlew assembleRelease",
Result image
in apk
-in simple virtual machine
I switched from react native navigation v1 to v2 and I have theses 5 errors when trying to sync my files with Android Studio.
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve project :react-native-navigation.
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve project :react-native-navigation.
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve project :react-native-navigation.
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve project :react-native-navigation.
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve project :react-native-navigation.
I tried to clear .iml files and .idea folder, invalidate caches and restart.
Configuration:
react-native: 0.51.0,
react-native-navigation: ^2.4.0,
Android Studio: 3.1.1
Android build.gradle
buildscript {
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
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' }
jcenter()
}
}
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 19
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
}
subprojects { subproject ->
afterEvaluate {
if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
variantFilter { variant ->
def names = variant.flavors*.name
if (names.contains("reactNative55") || names.contains("reactNative56") || names.contains("reactNative57")) {
setIgnore(true)
}
}
}
}
}
}
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
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
missingDimensionStrategy "RNN.reactNativeVersion", "reactNative51"
multiDexEnabled true
versionCode 723
versionName "1.72"
ndk {
abiFilters "armeabi-v7a", "x86"
}
versionNameSuffix '3'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
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"
signingConfig signingConfigs.release
}
}
// 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
}
}
}
productFlavors {
}
}
dependencies {
compile project(':react-native-appsflyer')
compile project(':react-native-text-input-reset')
compile project(':bugsnag-react-native')
compile project(':react-native-version-check')
compile project(':react-native-video')
compile project(':react-native-intercom')
compile project(':react-native-fast-image')
compile project(':react-native-device-info')
compile project(':react-native-rate')
compile(project(':react-native-firebase')) {
transitive = false
}
compile project(':react-native-fbsdk')
compile project(':react-native-linear-gradient')
implementation fileTree(dir: "libs", include: ["*.jar"])
compile 'com.facebook.android:facebook-android-sdk:4.29.0'
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
// From node_modules
compile 'com.facebook.fresco:animated-gif:1.3.0'
implementation project(':react-native-navigation')
// Firebase dependencies
compile 'com.google.android.gms:play-services-base:11.6.0'
compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.firebase:firebase-auth:11.6.0'
compile 'com.google.firebase:firebase-firestore:11.6.0'
compile(project(':react-native-maps')) {
exclude group: 'com.google.android.gms'
}
compile('com.google.android.gms:play-services-base:11.6.0') {
force = true;
}
compile('com.google.android.gms:play-services-maps:11.6.0') {
force = true;
}
compile('com.google.android.gms:play-services-gcm:11.6.0') {
force = true;
}
implementation "com.google.firebase:firebase-analytics:11.6.0"
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation project(':react-native-fbsdk')
implementation "com.google.firebase:firebase-messaging:11.6.0"
implementation 'me.leolin:ShortcutBadger:1.1.21#aar'
}
// 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 plugin: 'com.google.gms.google-services'
MainActivity.java
package com.myapp;
import com.reactnativenavigation.NavigationActivity;
import android.content.Intent;
import com.appsflyer.AppsFlyerLib;
import com.appsflyer.AppsFlyerConversionListener;
public class MainActivity extends NavigationActivity {
/**
* 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
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
}
MainApplication.java
package com.myapp;
import com.BV.LinearGradient.LinearGradientPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
// import com.facebook.react.shell.MainReactPackage;
// import com.facebook.soloader.SoLoader;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;
import com.nikolaiwarner.RNTextInputReset.RNTextInputResetPackage;
import com.reactlibrary.RNRatePackage;
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import com.airbnb.android.react.maps.MapsPackage;
import io.xogus.reactnative.versioncheck.RNVersionCheckPackage;
import com.bugsnag.BugsnagReactNative;
import com.brentvatne.react.ReactVideoPackage;
import com.dylanvann.fastimage.FastImageViewPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.robinpowered.react.Intercom.IntercomPackage;
import io.intercom.android.sdk.Intercom;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.app.Activity;
// import com.reactnativenavigation.controllers.ActivityCallbacks;
// import com.facebook.react.ReactApplication;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import com.appsflyer.reactnative.RNAppsFlyerPackage;
public class MainApplication extends NavigationApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#Override
protected ReactGateway createReactGateway() {
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
#Override
protected String getJSMainModuleName() {
return "index";
}
};
return new ReactGateway(this, isDebug(), host);
}
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// new MainReactPackage(),
new RNAppsFlyerPackage(MainApplication.this),
new RNTextInputResetPackage(),
BugsnagReactNative.getPackage(),
new RNVersionCheckPackage(),
new ReactVideoPackage(),
new IntercomPackage(),
new FastImageViewPackage(),
new RNDeviceInfo(),
new RNRatePackage(),
new RNFirebasePackage(),
new RNFirebaseMessagingPackage(),
new FBSDKPackage(mCallbackManager),
new LinearGradientPackage(),
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
AppEventsLogger.activateApp(this);
Intercom.initialize(this, "android_sdk-mykey", "mykey");
BugsnagReactNative.start(this);
setActivityCallbacks(new ActivityCallbacks() {
#Override
public void onActivityResumed(Activity activity) {
// Do stuff
}
#Override
public void onActivityPaused(Activity activity) {
// Do stuff
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
});
FacebookSdk.sdkInitialize(getApplicationContext());
SoLoader.init(this, /* native exopackage */ false);
}
#Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
#Nullable
#Override
public List<ReactPackage> createAdditionalReactPackages() {
return Arrays.<ReactPackage>asList(
new RNTextInputResetPackage(),
// new MainReactPackage(),
BugsnagReactNative.getPackage(),
new RNVersionCheckPackage(),
new RNRatePackage(),
new RNFirebasePackage(),
new RNFirebaseAuthPackage(),
new RNFirebaseFirestorePackage(),
new RNFirebaseAnalyticsPackage(),
new RNFirebaseMessagingPackage(),
// new RNFirebaseNotificationsPackage(),
new RNDeviceInfo(),
new ReactVideoPackage(),
new IntercomPackage(),
new FastImageViewPackage(),
new MapsPackage(),
new FBSDKPackage(mCallbackManager),
new LinearGradientPackage(),
new RNAppsFlyerPackage(MainApplication.this)
);
}}
My settings.gradle
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/lib/android')
And gradle-wraper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Sorry for the long code but I maybe made a mistake somewhere.
It looks like the RNN module is not present.
Quick checklist to resolve this:
1) Check package.json, it should contain in its dependencies "react-native-navigation": "^2.11.0", or another similar version. If it does not, the module will need to be (re-)installed. Use npm install --save react-native-navigation, or yarn equivalent.
2) Check inside the directory ./node_modules/react-native-navigation. If it only contains 'lib/android/app/<single file>', your module may have been deleted. If so, npm install / yarn install should recover it.
I build React Native Released Version and publish it Google Play Store.
But it doesn't work.
Do not move to next HomeScreen from SplashScreen.
So I test with My Android Emulator and suddenly Meteor JS Bundle Run on Terminal and works like Debug version.
Similiar with this bug
https://github.com/facebook/react-native/issues/16793
But solution of this link doesn't work for me.
The solution is to remove "import com.facebook.react.BuildConfig;" line, but I don't have.
This is the code of MainApplication
package org.sharingappforstudent;
import android.app.Application;
import com.crashlytics.android.Crashlytics;
import com.facebook.react.ReactApplication;
import org.devio.rn.splashscreen.SplashScreenReactPackage;
import org.wonday.pdf.RCTPdfView;
import com.RNFetchBlob.RNFetchBlobPackage;
import cl.json.RNSharePackage;
import com.reactlibrary.RNMailCorePackage;
import com.magus.fblogin.FacebookLoginPackage;
import com.reactnative.ivpusic.imagepicker.PickerPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.imagepicker.ImagePickerPackage;
import io.fabric.sdk.android.Fabric;
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.storage.RNFirebaseStoragePackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import com.airbnb.android.react.maps.MapsPackage;
import com.AlexanderZaytsev.RNI18n.RNI18nPackage;
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 SplashScreenReactPackage(),
new RCTPdfView(),
new RNFetchBlobPackage(),
new RNSharePackage(),
new RNMailCorePackage(),
new FacebookLoginPackage(),
new PickerPackage(),
new VectorIconsPackage(),
new ImagePickerPackage(),
new RNFirebasePackage(),
new RNI18nPackage(),
new RNFirebaseStoragePackage(),
new RNFirebaseAuthPackage(),
new RNFirebaseDatabasePackage(),
new RNFirebaseMessagingPackage(),
new MapsPackage()
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
SoLoader.init(this, /* native exopackage */ false);
}
}
app/build.gradle file
apply plugin: "com.android.application"
apply plugin: 'io.fabric'
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 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "org.sharingappforstudent"
minSdkVersion 23
targetSdkVersion 23
versionCode 11
versionName "1.3"
ndk {
abiFilters "armeabi-v7a", "x86"
}
multiDexEnabled true
}
// (!!!ATTENTION!!!) FIX FOR MAIL CORE DEPENDENCIES (!!!DO NOT REMOVE!!!)
packagingOptions {
pickFirst 'lib/armeabi-v7a/libgnustl_shared.so'
pickFirst 'lib/arm64-v8a/libgnustl_shared.so'
pickFirst 'lib/x86_64/libgnustl_shared.so'
pickFirst 'lib/x86/libgnustl_shared.so'
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
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"
signingConfig signingConfigs.release
}
}
// 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
}
}
}
dexOptions {
jumboMode true
}
}
dependencies {
compile project(':react-native-splash-screen')
compile project(':react-native-pdf')
compile project(':react-native-fetch-blob')
compile project(':react-native-share')
compile(project(':react-native-mailcore'))
compile project(':react-native-facebook-login')
compile project(':react-native-image-crop-picker')
compile project(':react-native-vector-icons')
compile project(':react-native-image-picker')
compile (project(':react-native-maps')) {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
compile project(':react-native-i18n')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.google.firebase:firebase-messaging:12.0.0"
compile project(':react-native-facebook-login')
compile(project(':react-native-firebase')) {
transitive = false
}
// Firebase dependencies
compile "com.google.android.gms:play-services-base:12.0.0"
compile 'com.google.android.gms:play-services-maps:12.0.0'
compile "com.google.firebase:firebase-core:12.0.0"
compile "com.google.firebase:firebase-storage:12.0.0"
compile "com.google.firebase:firebase-auth:12.0.0"
compile "com.google.firebase:firebase-database:12.0.0"
compile "me.leolin:ShortcutBadger:1.1.21#aar"
compile('com.crashlytics.sdk.android:crashlytics:2.9.0#aar') {
transitive = true
}
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
Need help.
Thanks.