I've added SQLite in build.gradle:
dependencies {
compile 'org.xerial:sqlite-jdbc:3.8.9.1'
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.xerial:sqlite-jdbc:3.8.9.1'
}
}
Once I want to connect to SQLite DB in code:
groovy.sql.Sql.newInstance(dbLocation, "org.sqlite.JDBC")
It complains that :
java.lang.ClassNotFoundException: org.sqlite.JDBC
What is the reason? How can I fix it?
The problem is that you need to get the JDBC drivers into the root classloader rather than just being on the generalised classpath.
You have a few options. One of them is to use your own configuration, and then manipulate the root classloader via GroovyObject:
import groovy.sql.Sql
configurations {
sqllite
}
repositories {
mavenCentral()
}
dependencies {
sqllite 'org.xerial:sqlite-jdbc:3.8.9.1'
}
URLClassLoader loader = GroovyObject.class.classLoader
configurations.sqllite.each { File file ->
loader.addURL(file.toURL())
}
Sql sql = Sql.newInstance('jdbc:sqlite:test.db', "org.sqlite.JDBC")
task checkSql << {
sql.execute 'CREATE TABLE TIM(name CHAR(50))'
sql.eachRow('SELECT * FROM sqlite_master') { row ->
logger.lifecycle row.toString()
}
}
Then running gradle checkSql should result in:
$ gradle checkSql
:checkSql
[type:table, name:TIM, tbl_name:TIM, rootpage:2, sql:CREATE TABLE TIM(name CHAR(50))]
BUILD SUCCESSFUL
Total time: 4.374 secs
At least, it does in Gradle 2.9
Related
I have tried to change the name of the item and it doesn't work
o ya my lang file doesn't work too
error:
Exception loading model for variant rpc:ingot_titinium#inventroy for item "rpc:ingot_titinium", normal location exception
https://pastebin.com/WnNGPAGZ
public void registerModel(Item item, int metadata)
{
ModelLoader.setCustomModelResourceLocation(item, metadata, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}
edit:
folder structure and ref code
if you're using intellij idea, add at the bottom of your build.gradle file:
sourceSets { main { output.resourcesDir = output.classesDir } }
Expected
The Kotlin app running in IntelliJ has been migrated from a 2009 MacBook Pro to a 2019 MacBook Pro. Provided the same credentials, the project is expected to run identical code accessing both a Firestore database and Firestore Storage.
Observed
The code will not run on the new machine due to oauth errors.
Errors
com.google.api.gax.grpc.InstantiatingGrpcChannelProvider does not define or inherit an implementation of the resolved method abstract needsCredentials()
Failed to detect whether we are running on Google Compute Engine.
Log
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Jul 07, 2019 11:45:41 AM com.google.auth.oauth2.ComputeEngineCredentials runningOnComputeEngine
INFO: Failed to detect whether we are running on Google Compute Engine.
Exception in thread "Timer-0" java.lang.AbstractMethodError: Receiver class com.google.api.gax.grpc.InstantiatingGrpcChannelProvider does not define or inherit an implementation of the resolved method abstract needsCredentials()Z of interface com.google.api.gax.rpc.TransportChannelProvider.
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:157)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:122)
at com.google.cloud.firestore.spi.v1beta1.GrpcFirestoreRpc.<init>(GrpcFirestoreRpc.java:121)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:80)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:72)
at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:510)
at com.google.cloud.firestore.FirestoreOptions.getFirestoreRpc(FirestoreOptions.java:315)
at com.google.cloud.firestore.FirestoreImpl.<init>(FirestoreImpl.java:76)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:63)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:56)
at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:498)
at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:51)
at com.google.firebase.cloud.FirestoreClient.<init>(FirestoreClient.java:29)
at com.google.firebase.cloud.FirestoreClient$FirestoreClientService.<init>(FirestoreClient.java:95)
at com.google.firebase.cloud.FirestoreClient.getInstance(FirestoreClient.java:85)
at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:78)
at com.google.firebase.cloud.FirestoreClient.getFirestore(FirestoreClient.java:64)
at utils.FirebaseClient.<clinit>(FirebaseClient.kt:10)
at utils.FirestoreCollectionsKt.<clinit>(FirestoreCollections.kt:5)
at content.ContentTasks.getExistingContentSet(ContentTasks.kt:89)
at content.ContentTasks.run(ContentTasks.kt:39)
at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
at java.base/java.util.TimerThread.run(Timer.java:506)
Process finished with exit code 0
Existing Code for Authentication
Initialization.kt
object Initialization {
#JvmStatic
fun main(args: Array<String>) {
set(Enums.EnvironmentType.STAGING)
initializeFirestore()
getContent()
}
private fun initializeFirestore() {
FirebaseApp.initializeApp(FirebaseOptions.Builder()
.setCredentials(fromStream(Gson().toJson(getFirebaseCredentials()).byteInputStream()))
.setFirestoreOptions(FirestoreOptions.newBuilder().setTimestampsInSnapshotsEnabled(true).build())
.build())
}
}
CredentialsHelper.kt
fun getFirebaseCredentials() =
if (environmentType == PRODUCTION) FirebaseCredentials(
"service_account",
"[projectId]",
"[privateKeyId]",
"[privateKey]",
"[clientEmail]",
"[clientId]",
"https://accounts.google.com/o/oauth2/auth",
"https://accounts.google.com/o/oauth2/token",
"https://www.googleapis.com/oauth2/v1/certs",
"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-0z4rn%40carpecoin-media-211903.iam.gserviceaccount.com")
else FirebaseCredentials(
"service_account",
"[projectId]",
"[privateKeyId]",
"[privateKey]",
"[clientEmail]",
"[clientId]",
"https://accounts.google.com/o/oauth2/auth",
"https://accounts.google.com/o/oauth2/token",
"https://www.googleapis.com/oauth2/v1/certs",
"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-dhr30%40coinverse-media-staging.iam.gserviceaccount.com")
Attempted Solution
Updating library versions in build.gradle in case the issue is due to a dependency conflict.
build.gradle
buildscript {
ext.kotlin_version = '1.3.41'
ext.junitJupiterVersion = '5.5.0'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'junit', name: 'junit', version: '5.3.2'
// JUnit Jupiter API and TestEngine implementation
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
testImplementation "org.assertj:assertj-core:3.12.2"
// To avoid compiler warnings about #API annotations in JUnit code
testCompileOnly 'org.apiguardian:apiguardian-api:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.6.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
implementation 'com.google.firebase:firebase-admin:6.8.1'
implementation 'com.google.cloud:google-cloud-storage:1.79.0'
implementation 'com.google.apis:google-api-services-youtube:v3-rev212-1.25.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
This is because that a "gax" on which "firebase-admin" depends via "gax-grpc" is old so a newer "gax" which other library, perhaps "google-cloud-storage" in your case, introduces is selected by Gradle, resulting in compatibility issue.
In my case, forcing Gradle to use the latest "gax-grpc" like the following got the problem fixed. I hope this helps you as well.
implementation group: 'com.google.api', name: 'gax-grpc', version: '1.47.1'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.1.1'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'https://mvnrepository.com/artifact/com.caucho/hessian'
}
maven {
url'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.demoapp.DemoApp'
dependencies {
compile 'com.gluonhq:charm:4.1.0'
compile 'com.airhacks:afterburner.mfx:1.6.2'
compile 'com.caucho:hessian:4.0.7'
compile 'com.google.code.gson:gson:2.3.1'
compile 'org.apache.poi:poi:3.9'
}
jfxmobile {
downConfig {
version '3.0.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.demoapp.**.*',
'com.gluonhq.**.*',
'io.datafx.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*',
'com.caucho.**.*',
'com.google.code.gson.**.*',
'org.apache.poi.**.*'
]
}
}
Error Exception in Application init method
QuantumRenderer: shutdown
java.lang.RuntimeException: Exception in Application init method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:109069952)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java:109069952)
at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)
at java.lang.Thread.run(Thread.java:109069952)
Caused by: java.lang.NoSuchMethodError: com.demoapp.DemoApp$$Lambda$1.()V
at com.demoapp.DemoApp.init(DemoApp.java:109070784)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:109070784)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java:109070784)
at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)
at java.lang.Thread.run(Thread.java:109070784)
Any idea where to search for the init-Error when deploying..? Thanks.
Init:
#Override
public void init() {
NavigationDrawer drawer = new NavigationDrawer();
NavigationDrawer.Header header = new NavigationDrawer.Header("demo inc", "smart teamwork", new Avatar(21, new Image(DemoApp.class.getResourceAsStream("/icon.png"))));
drawer.setHeader(header);
drawer.getItems().addAll(primaryItem, secondaryItem, thirdItem);
primaryItem.setSelected(true);
addViewFactory(PRIMARY_VIEW, () -> (View) new PrimaryView().getView());
addViewFactory(SECONDARY_VIEW, () -> (View) new SecondaryView().getView());
addViewFactory(THIRD_VIEW, () -> (View) new ThirdView().getView());
addLayerFactory(MENU_LAYER, () -> new SidePopupView(drawer));
}
#Override
public void postInit(Scene scene) {
Swatch.ORANGE.assignTo(scene);
scene.getStylesheets().add(DemoApp.class.getResource("style.css").toExternalForm());
((Stage) scene.getWindow()).getIcons().add(new Image(DemoApp.class.getResourceAsStream("/icon.png")));
switchView(SECONDARY_VIEW);
}
The exception shows that a lambda expression is failing. Probably those in your init method with the view suppliers.
Possible reasons for this exception are:
Retrolambda
The jfxmobile plugin since version 1.1.0 applies retrolambda to all the dependencies. But you can't apply it twice.
The first step will be checking which dependencies might use retrolambda.
Charm 4+ doesn't use it. Afterburner 1.6.2 does, so either you change it to:
dependencies {
compileNoRetrolambda 'com.airhacks:afterburner.mfx:1.6.2'
}
or you use the brand new version that excludes it:
dependencies {
compile 'com.airhacks:afterburner.mfx:1.6.3'
}
To make sure none of the other dependencies use it, replace compile with compileNoRetrolambda in hessian, gson and poi.
Cache
Also, when updating projects with lower versions of the jfxmobile plugin, it is possible that you have a previous build on your cache. This might contain classes that you compiled with retrolambda.
While the code is the same, Gradle will skip compiling them again, but when the retrolambda plugin is applied again over them, this will fail.
To avoid this problem, an easy solution is using clean before building and deploying your project: Run ./gradlew clean launchIOSDevice.
I had a project library in Eclipse with Maven and the generated jar included some libraries dependencies inside.
Now I am migrating to Android Studio and I would like to build the same jar. I can generate a jar with the following lines in gradle:
task clearJar(type: Delete) {
delete 'build/libs/mysdk.jar'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
rename ('classes.jar', 'mysdk.jar')
}
makeJar.dependsOn(clearJar, build)
But inside the jar there are not included the libraries that I use in my project library. With Maven I can use the "provided" scope in order to include or not a library in my jar but with gradle... how can I do that?
Thanks
Solved with the following tasks:
task jarTask(type: Jar) {
baseName="my-sdk-android"
from 'src/main/java'
}
task createJarWithDependencies(type: Jar) {
baseName = "my-sdk-android-jar-with-dependencies"
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
with jarTask
}
configurations {
jarConfiguration
}
artifacts {
jarConfiguration jarTask
}
I created a new project using Android Studio and copied a jar file into my application's libs. Then added it as a library, which made the IDE recognize it. Later, I added it to the build.gradle and it now compiles just fine. However, when I attempt to run the application on a device it crashes with NoClassDefFoundError.
Attached and in order:
The project tree on Android Studio. Notice the test-jar-to-import.jar inside HelloSheepProject/HelloSheep/libs/.
The contents of the MainActivity.java. It is attempting to create a new MyFile. Nothing else.
The build.gradle inside HelloSheepProject/HelloSheep/. I added the line compile files('libs/test-jar-to-import.jar').
The contents of MyFile.java. It was created in Eclipse and exported as a jar file.
The error when I trying to run it on a device.
Any ideas on what I am missing? I have tried a ./gradlew clean in HelloSheepProject but it didn't help.
package top.furrylamb.example.hellosheep;
import android.os.Bundle;
import android.app.Activity;
import top.furrylamb.example.MyFile;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyFile myFile = new MyFile("hi", "there");
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
//compile fileTree(dir: "libs", include: "*.jar")
compile files('libs/test-jar-to-import.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
package top.furrylamb.example;
public class MyFile {
public final String left;
public final String right;
public MyFile(String left, String right) {
this.left = left;
this.right = right;
}
}
07-19 19:26:33.855 13656-13656/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: top.furrylamb.example.MyFile
at top.furrylamb.example.hellosheep.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
I found the solution to my problem. Since I've been lost on this for hours I'll keep the thread instead of deleting it.
The jar I was importing had been compiled/exported with Java 7 in mind. Once I enabled compliance with Java 6 it worked fine.
To sum it up, when adding an external jar file in Android Studio:
Copy jar to root/project/libs folder;
Right-click and add as library;
Add the jar to root/project/build.gradle (something like compile files('libs/test-jar-to-import.jar'));
Make sure the imported jar complies with Java 6 (7 will not do, for now).
In my case, I was getting the same NoClassDefFoundError error at runtime, even though it compiled ok. It had been working fine previously. But one day, I added a new package to my app, which resulted in the package name-space being changed. My jar had already been a part of the application's structure, so I was somewhat surprised at this new runtime error suddenly complaining about an unknown class in a jar library that was working previously.
The fix, in my case, was a simple Build->Clean Project.