Related
I am trying to add data to firestore. and also i want to do this using dagger. but i keep getting this error. can you help me please......
** Default FirebaseApp is not initialized in this process com.example.vvvv. Make sure to call FirebaseApp.initializeApp(Context) first. **
FirestoreREpository
class FirestoreRepository #Inject constructor(private val usersRef:
CollectionReference) {
fun saveSearchResults(userEntities: List<UserEntity>) {
usersRef.add(userEntities).addOnCompleteListener { task ->
when (task.isSuccessful) {
true -> Log.d(ContentValues.TAG, "added:success")
false -> Log.d(ContentValues.TAG, "added:unsuccess")
}
}
}
}
ViewModel
#HiltViewModel
class UserListViewModel #Inject constructor(private val repository: RoomRepository, private
val firestoreRepository: FirestoreRepository) :
ViewModel() {
private val _users = MutableLiveData<List<User>>()
val users: LiveData<List<User>>
get() = _users
var userData: MutableLiveData<List<User>> = MutableLiveData()
fun userSearch(term: String) {
viewModelScope.launch {
loadFromCache(term)
val getPropertiesDeferred =
GithubApi.retrofitService.searchUser(term)
try {
val userEntities: MutableList<UserEntity> = mutableListOf()
val result = getPropertiesDeferred.body()
_users.value = result?.users
result?.users?.forEach {
userEntities.add(
UserEntity(
term = term,
login = it.login,
avatar_url = it.avatar_url
)
)
}
clearSearchResults(term)
updateSearchResults(userEntities, term)
firestoreRepository.saveSearchResults(userEntities) //save
data with firebase
} catch (e: Exception) {
Log.e("userListErr", e.message.toString())
}
}
}
private fun updateSearchResults(userEntities: List<UserEntity>, term:
String) {
viewModelScope.launch(Dispatchers.IO) {
repository.insertSearchResults(userEntities)
loadFromCache(term)
}
}
private fun loadFromCache(term: String) {
viewModelScope.launch(Dispatchers.IO) {
val list = repository.getSearchResults(term)
userData.postValue(list)
}
}
private fun clearSearchResults(term: String) {
viewModelScope.launch(Dispatchers.IO) {
repository.deleteSearchResults(term)
}
}
}
AppModule
#Module
#InstallIn(SingletonComponent::class)
object APPModule {
#Singleton
#Provides
fun getAppDB(context: Application): AppDatabase {
return AppDatabase.getAppDB(context)
}
#Singleton
#Provides
fun getDao(appDB: AppDatabase): AppDao {
return appDB.getDAO()
}
#Provides
fun provideFirebaseFirestore() = FirebaseFirestore.getInstance()
#Provides
fun provideUsersRef(db: FirebaseFirestore) = db.collection("users")
}
I used multi-module in this project. id com.google.gms.google-services to app directory and solved.
In build.gradle(project) in dependencies add the following:
classpath 'com.google.gms:google-services:4.3.5'
In build.gradle(module) add the following:
plugins {
id 'com.google.gms.google-services'
}
in your last line of code add the following:
apply plugin: 'com.google.gms.google-services'
I meet this problem, because google-service sdk version not work with gradle version.
Maybe you can try with this direction.
The original project build.gradle config is ok.
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:3.2.1"
classpath 'com.google.gms:google-services:4.1.0'
Finally, it's solve by find compatible SDK version.
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:3.3.3"
classpath 'com.google.gms:google-services:4.2.0'
I am having trouble connecting react-native-firebase into my react-native project. It is installed and firebase has shown me that it is connected, however now I am trying to use the RNFirebaseAuthPackage.
I have received the error message that tells me I need to install/import the Firebase Android SDK dependency in my android/app/build.gradle, RNFirebaseAuthPackage module in my MainApplication.java and the RNFirebaseAuthPackage() inside of the getPackages()
Here is my android/app/build.gradle file
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
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.v4"
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", "x86_64"
}
}
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, "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-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
//Firebase dependencies
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.firebase:firebase-core:16.0.9"
implementation "com.google.firebase:firebase-auth"
}
// 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'
And here is my MainApplication.java file.
package com.v4;
import android.app.Application;
import com.facebook.react.ReactApplication;
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.RNFirebaseAuthPackage;
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 RNFirebasePackage(),
new RNFirebaseAuthPackage()
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
And I'm not sure if it is really needed, but just incase anyways here is my project build.gradle file.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
The error I am getting when I try to sync the project in android studio is
Failed to resolve: com.google.firebase:firebase-auth:
I'm not too sure where to go from here, sorry for the copy and pasted files, I am just quite stuck.
Any help is much appreciated.
An attempt of solution is to replace this :
implementation "com.google.firebase:firebase-auth"
by this
implementation "com.google.firebase:firebase-auth:16.1.0"
in your android/app/build.gradle file.
I am facing same issue but after changing i am solving this problem follow these step and solve your issue
Run the following command
Step 1: npm install react-native-google-signin --save
Linking of Library
Step 2:react-native link
You can see the following changes in your android project. If you are unable to find the changes then please do those changes as they are must for this example.
Go to the GoogleSigninExample> android > app > build.gradle.
Scroll down and you can see the following dependency and if not please add this.
**compile project(':react-native-google-signin')**
Open GoogleSigninExample> android > settings.gradle and you can see the following lines and if not please add this.
include ':react-native-google-signin'
project(':react-native-google-signin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-signin/android')
Open GoogleSigninExample> android > app > src > main > java > com > googlesigninexample> MainApplication.java and you can see the following lines in imports if not then please add
import co.apptailor.googlesignin.RNGoogleSigninPackage;
Scroll down and you can see the following line in getPackages after new MainReactPackage() if not then please add a comma(,) and add
new RNGoogleSigninPackage()
if you are follow these step then you can solve your issue.
and i will show my MainApplication.java
package com.uiapp;
import android.app.Application;
import co.apptailor.googlesignin.RNGoogleSigninPackage;
import com.facebook.react.ReactApplication;
import com.inprogress.reactnativeyoutube.ReactNativeYouTube;
import co.apptailor.googlesignin.RNGoogleSigninPackage;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.imagepicker.ImagePickerPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.inprogress.reactnativeyoutube.ReactNativeYouTube;
import com.facebook.FacebookSdk;
import com.facebook.CallbackManager;
import com.facebook.appevents.AppEventsLogger;
import android.content.Intent;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
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 ReactNativeYouTube(),
new RNGoogleSigninPackage(),
new FBSDKPackage(mCallbackManager),
new ImagePickerPackage(),
new RNGestureHandlerPackage()
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
// #Override
// public void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
// MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
// }
}
and see the android/build.gradlew
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.0")
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
and code of setting.gradlew
rootProject.name = 'UiApp'
include ':react-native-youtube'
project(':react-native-youtube').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-youtube/android')
include ':react-native-google-signin'
project(':react-native-google-signin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-signin/android')
include ':react-native-fbsdk'
project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':app'
include ':react-native-google-signin'
project(':react-native-google-signin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-signin/android')
include ':react-native-youtube'
project(':react-native-youtube').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-youtube/android')
Also see the code of android/app/build.gradlew
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 call `react-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 = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.uiapp"
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", "x86_64"
}
}
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, "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-google-signin')
implementation project(':react-native-fbsdk')
implementation project(':react-native-image-picker')
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'
}
I want to put the application version to my gluon application. but I don't know how to do. Do I need to create service for that?
There is a very simple approach, that doesn't required a service, but it can lead to errors:
You can maintain a version code/version number for Android in the AndroidManifest:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package"
android:versionCode="1.1.0"
android:versionName="1.1.0">
The same on iOS, in the Default-Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>your.bundle.identifier</string>
<key>CFBundleVersion</key>
<string>1.1.0</string>
And finally you can keep a static field in your code:
public static final String VERSION_NAME = "1.1.0";
that you can access from the NavigationDrawer, for instance.
However this requires manual updating every time you make a new release.
To avoid errors, you can set some CI job that does it for you. See for instance this commit, that it is part of the release job of a mobile app.
Charm Down Service
However, a more definitive way of avoiding mismatches between the released versions and the variable in your code is by adding a service that directly reads those versions.
Something like this:
VersionService.java
package com.gluonhq.charm.down.plugins;
public interface VersionService {
String getVersionName();
}
VersionServiceFactory.java
package com.gluonhq.charm.down.plugins;
import com.gluonhq.charm.down.DefaultServiceFactory;
public class VersionServiceFactory extends DefaultServiceFactory<VersionService> {
public VersionServiceFactory() {
super(VersionService.class);
}
}
Android package, under src/android/java:
AndroidVersionService.java
package com.gluonhq.charm.down.plugins.android;
import android.content.pm.PackageManager;
import com.gluonhq.charm.down.plugins.VersionService;
import javafxports.android.FXActivity;
public class AndroidVersionService implements VersionService {
#Override
public String getVersionName() {
try {
return FXActivity.getInstance().getPackageManager()
.getPackageInfo(FXActivity.getInstance().getPackageName(), 0)
.versionName;
} catch (PackageManager.NameNotFoundException ex) { }
return "";
}
}
IOS package, under src/ios/java:
IOSVersionService.java
package com.gluonhq.charm.down.plugins.ios;
import com.gluonhq.charm.down.plugins.VersionService;
public class IOSVersionService implements VersionService {
static {
System.loadLibrary("Version");
}
#Override
public String getVersionName() {
return getNativeVersion();
}
private static native String getNativeVersion();
}
Under src/ios/native:
Version.m
#import <UIKit/UIKit.h>
#include "jni.h"
JNIEXPORT jint JNICALL
JNI_OnLoad_Version(JavaVM *vm, void *reserved)
{
#ifdef JNI_VERSION_1_8
//min. returned JNI_VERSION required by JDK8 for builtin libraries
JNIEnv *env;
if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) {
return JNI_VERSION_1_4;
}
return JNI_VERSION_1_8;
#else
return JNI_VERSION_1_4;
#endif
}
JNIEXPORT jstring JNICALL Java_com_gluonhq_charm_down_plugins_ios_IOSVersionService_getNativeVersion
(JNIEnv *env, jclass jClass)
{
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleVersion"];
return (*env)->NewStringUTF(env, [version cStringUsingEncoding:NSASCIIStringEncoding]);
}
Build files, at root level:
ios-build.gradle
if (System.getProperty('os.name').toLowerCase().contains("mac")) {
new ByteArrayOutputStream().withStream { os ->
exec {
args '-version', '-sdk', 'iphoneos', 'SDKVersion'
executable 'xcodebuild'
standardOutput = os
}
ext.IOS_VERSION = os.toString().trim()
}
} else {
ext.IOS_VERSION = ""
}
ext.IS_DEBUG_NATIVE = Boolean.parseBoolean(System.getProperty("IS_DEBUG_NATIVE", "false"))
def sdkPath(String platform) {
return "/Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}${IOS_VERSION}.sdk";
}
ext.xcodebuildIOS = {buildDir, projectDir, name ->
if (!file(sdkPath('iPhoneOS')).exists()) {
println "Skipping xcodebuild"
return
}
// define statics do being able to configure the input/output files on the task
// for faster builds if nothing changed
def buildSystems = ["iPhoneOS+arm64",
"iPhoneOS+armv7",
"iPhoneSimulator+i386",
"iPhoneSimulator+x86_64"]
def linkerOutputs = []
def lipoOutput = "$buildDir/native/lib${name}.a"
def nativeSources = ["$projectDir/src/ios/native/${name}.m"]
// the actual task action
buildSystems.each { buildSystem ->
def (platform, arch) = buildSystem.tokenize("+");
def compileOutput = "$buildDir/native/$arch"
def compileOutputs = ["$buildDir/native/$arch/${name}.o"]
def linkerOutput = "$buildDir/native/$arch/lib${name}.a"
new File(compileOutput).mkdirs();
def clangArgs = [
"-x", "objective-c",
"-miphoneos-version-min=6.0",
"-fmessage-length=0",
"-std=c99",
"-fno-common",
"-Wall",
"-fno-strict-aliasing",
"-fwrapv",
"-fpascal-strings",
"-fobjc-abi-version=2",
"-fobjc-legacy-dispatch",
"-I" + System.getenv("JAVA_HOME") + "/include",
"-I" + System.getenv("JAVA_HOME") + "/include/darwin",
"-c",
IS_DEBUG_NATIVE ? ["-O0", "-DDEBUG", "-g"] : ["-O3", "-DNDEBUG"],
"-arch", arch,
"-isysroot",
sdkPath(platform),
nativeSources].flatten()
// "-o", compileOutput,
def linkerArgs = [
"-static",
"-framework", "Foundation",
"-framework", "CoreGraphics",
"-framework", "CoreBluetooth",
"-framework", "CoreLocation",
"-framework", "CoreMotion",
"-framework", "CoreText",
"-framework", "UIKit",
"-framework", "QuartzCore",
"-framework", "OpenGLES",
"-framework", "UserNotifications",
"-arch_only", arch,
"-syslibroot", sdkPath(platform),
"-L${sdkPath(platform)}/usr/lib",
"-o", linkerOutput,
compileOutputs
].flatten()
// execute compiler
exec {
executable "clang"
args clangArgs
workingDir compileOutput
}
// execute linker
exec {
executable "libtool"
args linkerArgs
workingDir compileOutput
}
linkerOutputs.add(linkerOutput)
}
def lipoArgs = [
"-create",
linkerOutputs,
"-o",
lipoOutput
].flatten();
// execute lipo to combine all linker output in one archive
exec {
executable "lipo"
args lipoArgs
}
}
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.16'
}
}
apply plugin: 'org.javafxports.jfxmobile'
apply from: 'ios-build.gradle'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'your.main.class'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
}
jfxmobile {
javafxportsVersion = '8.60.11'
downConfig {
version = '3.8.6'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
task xcodebuild {
doLast {
xcodebuildIOS("$project.buildDir","$project.projectDir", "Version")
}
}
task installNativeLib (type:Copy, dependsOn: xcodebuild) {
from("$project.buildDir/native")
into("src/ios/jniLibs")
include("*.a")
}
Before deploying to iOS, run:
./gradlew installNativeLib
Service use
Finally, you can use the service anywhere in your code:
String version = Services.get(VersionService.class)
.map(VersionService::getVersionName)
.orElse(""));
this is with in a library module, so it should not use the generated API
upgrade to Glide 4.9.0
versions.glide = "4.9.0"
implementation "com.github.bumptech.glide:glide:$versions.glide"
kapt "com.github.bumptech.glide:compiler:$versions.glide"
implementation "com.github.bumptech.glide:annotations:$versions.glide"
updated the code, no place is using GlideApp
fun ImageView.loadImg(imageUrl: String) {
// 3.8.0
// if (!TextUtils.isEmpty(imageUrl)) {
// Glide.clear(this)
//
// Glide.with(context).load(imageUrl)
// .diskCacheStrategy(DiskCacheStrategy.ALL)
// .placeholder(ColorDrawable(Color.LTGRAY))
// .into(this)
// }
///
// 4.+ code
var requestOptions : RequestOptions = RequestOptions()
.placeholder(ColorDrawable(Color.LTGRAY))
.diskCacheStrategy(DiskCacheStrategy.ALL)
if (!TextUtils.isEmpty(imageUrl)) {
Glide.with(context)
.setDefaultRequestOptions(requestOptions)
.asBitmap()
.load(imageUrl)
.into(this)
}
}
fun ImageView.clear() {
Glide.with(this.context).clear(this)
}
got crash at Glide.with()
java.lang.AbstractMethodError: abstract method "void com.bumptech.glide.module.RegistersComponents.registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)"
at com.bumptech.glide.Glide.initializeGlide(Glide.java:270)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:223)
at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:184)
at com.bumptech.glide.Glide.get(Glide.java:168)
at com.bumptech.glide.Glide.getRetriever(Glide.java:689)
at com.bumptech.glide.Glide.with(Glide.java:716)
if adding the
#GlideModule
class DPAppGlideModule : AppGlideModule() {
override fun isManifestParsingEnabled(): Boolean {
return false
}
}
it will work, but since this is a library module so it should not have this one.
what might be the cause of AbstractMethodError: abstract method "void com.bumptech.glide.module.RegistersComponents.registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)"?
anything besides GlideApp should also be avoid?
turns out in this library module it has indirect dependency on someone who is using Glide3 and has Old GlideModule which does not impelenet the function required by the Glide 4.
Glide 4's module.registerComponents(applicationContext, glide, glide.registry); take 3 params, but Glide 3's has only two
for (com.bumptech.glide.module.GlideModule module : manifestModules) {
module.registerComponents(applicationContext, glide, glide.registry);
}
I'm using Thymeleaf.
This template:
<a th:href="#{/}">a</a>
produces this html:
a
This is what I'm expected.
I put ResourceUrlEncodingFilter bean to try ContentVersionStrategy in my WebMvcConfigurerAdapter extended class.
#Bean
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
return new ResourceUrlEncodingFilter();
}
The produced html turned to:
a
The value of href is empty.
I hope href is "/" even if I put ResourceUrlEncodingFilter bean.
th:href="#{/a}" turns to href="/a" in both cases.
Did I do something wrong?
Thank you very much.
UPDATE:
This is my build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE'
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.1.2.RELEASE'
}
}
dependencies {
compile('org.webjars:bootstrap:3.3.1')
compile('org.webjars:knockout:3.2.0')
compile('org.webjars:momentjs:2.9.0')
compile('org.webjars:numeral-js:1.5.3-1')
compile('org.webjars:underscorejs:1.7.0-1')
compile('org.webjars:sugar:1.4.1')
compile('org.webjars:jqplot:1.0.8r1250')
compile('org.webjars:jquery-cookie:1.4.1-1')
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-batch")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-tomcat")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework:spring-context-support") // this is for mail
compile('commons-codec:commons-codec')
compile("commons-io:commons-io")
compile('com.google.guava:guava')
compile('org.hibernate:hibernate-validator')
compile("com.sun.mail:javax.mail")
compile('mysql:mysql-connector-java')
compile("org.yaml:snakeyaml")
compile("org.apache.commons:commons-lang3:3.2")
compile('com.amazonaws:aws-java-sdk:1.9.4')
compile('net.sf.supercsv:super-csv:2.2.0')
compile('edu.vt.middleware:vt-password:3.1.2')
}
test {
//systemProperties 'property': 'value'
systemProperties 'spring.profiles.active': 'unittest'
systemProperties 'MAIL_PROP': 'mail.properties'
systemProperties 'user.timezone': 'UTC'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
Thanks for this detailed explanation and the repro project!
This is actually a bug: see SPR-13241, to be fixed in Spring 4.1.8 and 4.2.0.
Spring Boot adds "/**" matcher for automatic configurations of static web resources locations.
The locations are /META-INF/resources/, /resources/, /static/ and /public/.
When you put below html in Thymeleaf template,
<a th:href="#{/}">a</a>
Below method in ResourceUrlProvider.java is called because of the matcher and get into for loop:
public final String getForLookupPath(String lookupPath) {
// -- omission --
for(String pattern : matchingPatterns) {
// -- omission --
String pathWithinMapping = getPathMatcher().extractPathWithinPattern(pattern, lookupPath);
String pathMapping = lookupPath.substring(0, lookupPath.indexOf(pathWithinMapping));
// -- omission --
String resolved = chain.resolveUrlPath(pathWithinMapping, handler.getLocations());
if (resolved == null) {
continue;
}
// -- omission --
return pathMapping + resolved;
}
// -- omission --
}
The argument, lookupPath is "/" by the "#{/}", Then:
The pathWithinMapping will be "".
The pathMapping will be "".
The resolved will be "".
So this method returns "" and the value is set to href="".
This is in my opinion, if the pathWithinMapping is "", to continue the for loop seems good. Calling chain.resolveUrlPath seems not good.
Thanks,