Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react-native]After adding Sqlite to the project, Error occurs #294

Closed
Niks77 opened this issue Sep 16, 2018 · 15 comments · Fixed by #309
Closed

[react-native]After adding Sqlite to the project, Error occurs #294

Niks77 opened this issue Sep 16, 2018 · 15 comments · Fixed by #309

Comments

@Niks77
Copy link

Niks77 commented Sep 16, 2018

capture42

My React Native Project configuration is

{ "name": "AwesomeProject", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.5.0", "react-native": "0.57.0", "react-native-sqlite-storage": "^3.3.6" }, "devDependencies": { "babel-jest": "23.6.0", "jest": "23.6.0", "metro-react-native-babel-preset": "^0.45.0", "react-test-renderer": "16.5.0" }, "jest": { "preset": "react-native" } }

I am Writing Down What Instructions I followed, please Try to spot where I am wrong

In setting.gradle

rootProject.name = 'AwesomeProject'

include ':react-native-sqlite-storage' project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android')

include ':app'
`

In Android/app/build.gradle

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 compile project(':react-native-sqlite-storage') }

In MainApllication.java

...import org.pgsqlite.SQLitePluginPackage;...

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

Thankyou for helping Me
P.s :- Sorry of My Bad English

@filippoitaliano
Copy link

I've the same problem. I can't build for Android after configuring react-native-sqlite-storage. In my specific case the build fail with the error:

* What went wrong:
Could not resolve all files for configuration ':react-native-sqlite-storage:debugCompileClasspath'.
> Could not find support-v4.jar (com.android.support:support-v4:23.0.1).
  Searched in the following locations:
      https://jcenter.bintray.com/com/android/support/support-v4/23.0.1/support-v4-23.0.1.jar
> Could not find support-annotations.jar (com.android.support:support-annotations:23.0.1).
  Searched in the following locations:
      https://jcenter.bintray.com/com/android/support/support-annotations/23.0.1/support-annotations-23.0.1.jar

My environment

package.json

...
"dependencies": {
    "@babel/runtime": "7.1.2",
    "react": "16.5.0",
    "react-native": "0.57.1",
    "react-native-sqlite-storage": "3.3.6",
    "react-navigation": "2.17.0"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.47.0",
    "react-test-renderer": "16.5.0"
  },
...

android/settings.gradle

rootProject.name = 'GeoBadgeReactNative'

include ':app'

include ':react-native-sqlite-storage'
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android')

android/app/build.gradle

...
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

    compile project(':react-native-sqlite-storage')
}
...

android/app/src/main/java/com/appname

...
import org.pgsqlite.SQLitePluginPackage;

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 SQLitePluginPackage(), // register sqlite plugin here
          new MainReactPackage()
      );
    }
...

@filippoitaliano
Copy link

@Niks77 Have you found any solution?

@filippoitaliano
Copy link

filippoitaliano commented Oct 4, 2018

@andpor After some tries I was able to install and link correctly the package. It built in both android and IOS with no errors. Then trying to open a new db I discovered another problem: this one #285. I've reinstalled many times the package, in a clean rn project, following line by line the readme.

@sameer-kumar-jain
Copy link

@filippoitaliano If you are using prepopulated database then you may want to test this https://github.com/sameerjain/SQLiteDemo and see if that compile well and run as expected on android.

@filippoitaliano
Copy link

filippoitaliano commented Oct 5, 2018

@SameerJain Thank you! It doesn't build on IOS but it's very usefull!!

@sameer-kumar-jain
Copy link

@filippoitaliano yeah, I used cipher lib which needed extra steps to build on ios. But this should take you in right direction :)

@wolfjobs
Copy link

I solve my problem with upgrade the version of compileSdk&targetSdk to 26;

@filippoitaliano
Copy link

Sincerely I don't know why, but now it works really well. I have the same dependencies mentioned before. My compileSdk is 27 and my targetSdk is 26.

After installing deps I usually:

  1. rd /s/q node_modules
  2. del yarn.lock
  3. yarn cache clean
  4. rd /s/q android\.gradle (mind the dot)
  5. rd /s/q android\app\build
  6. Drop temporary system files related to node, haste, yarn, watchman ec...
  7. On Mac only watchman watch-del-all
  8. yarn && cd android && gradlew clean && cd..
  9. Eventually kill all processes that run on port 8081 or run the bundler on a different port

and I start the bundler separately:

  • yarn start --reset-cache
  • react-native run-android or ios (on ios sometimes I have to run this twice before it works)

@tonycapone
Copy link

tonycapone commented Dec 10, 2018

Has anyone fixed this? It looks like the problem is that jcenter is missing the gradle dependency and that is the only repository listed in the build.gradle

repositories {
jcenter()
}

@spruce-bruce
Copy link
Contributor

spruce-bruce commented Dec 10, 2018

I've been using this lib for close to a year now with minimal problems, but my builds are suddenly spitting out this error (starting 3 days ago on friday).

Is the issue that jcenter dropped that dep and this lib has no way of resolving it otherwise?

@spruce-bruce
Copy link
Contributor

@tonycapone The PR I submitted fixed the issue for me. For now I've got "react-native-sqlite-storage": "git://github.com:spruce-bruce/react-native-sqlite-storage.git#resolve-gradle-dep", in my package.json and that allows my builds to succeed. Once my PR is merged I'll be able to switch back to the npm module

@DedoJr
Copy link

DedoJr commented Jul 5, 2019

@filippoitaliano
...
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-sqlite-storage')

}
...

@filippoitaliano
Copy link

@DedoJr Yeah, we are in 2019.

@agatheLG
Copy link

agatheLG commented Sep 9, 2019

Hi, I had a lot of dependencies errors after trying to install react-native-sqlite-storage and i solved it by changing the path in the settings.gradle : I replace
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android')
by
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/platforms/android')

Another thing was that I didn't put anything in the mainApplication file, I din't add any package, which gives me this :
@OverRide
protected List getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}

I hope it helps

@ironbunny-ib
Copy link

Which settings.gradle?
I do not have any mention of react native sqlite storage in my android/settings.gradle

rootProject.name = 'LoveCopy' apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants