Kotlin collections throw ClassNotFoundException on Android - android

Using any of the lines below throws a ClassNotFoundException when app is run on Android.
val list = listOf("a", "b")
val arrayList = arrayListOf("a", "b")
val map = mapOf("key" to "value")
The exception:
04-28 15:12:00.770 27326-27326/com.example.kotlin E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kotlin, PID: 27326
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/collections/CollectionsKt;
at com.example.kotlin.MainActivity.onCreate(MainActivity.kt:17)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.collections.CollectionsKt" on path: DexPathList[[zip file "/data/app/com.example.kotlin-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.kotlin-1/lib/x86, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.example.kotlin.MainActivity.onCreate(MainActivity.kt:17) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Suppressed: java.lang.ClassNotFoundException: kotlin.collections.CollectionsKt
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 14 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
The following is my app module gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc3"
defaultConfig {
applicationId "com.example.kotlin"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:gridlayout-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
kapt 'com.android.databinding:compiler:2.1.0-beta3'
}
buildscript {
ext.kotlin_version = '1.0.1-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
kapt {
generateStubs = true
}
Is there any other dependency I need to add to gradle in order to use any of the Kotlin collection classes?

You need to depend on the Kotlin standard library which contains these classes:
dependencies {
/* ... */
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

Related

Didn't find class "org.osgi.framework.SynchronousBundleListener" in typesense Client Configuration

I added typesense jar libraries in to the my anroid project and getting crash when calling the client configuration.
Stacktrace
FATAL EXCEPTION: main
Process: com.soho.mytypesense, PID: 30422
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/osgi/framework/SynchronousBundleListener;
at org.glassfish.jersey.internal.ServiceFinder.find(ServiceFinder.java:265)
at org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:143)
at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:509)
at org.typesense.api.ApiCall.<init>(ApiCall.java:53)
at org.typesense.api.Client.<init>(Client.java:27)
at com.soho.mytypesense.MainActivity.callTypeSense(MainActivity.kt:55)
at com.soho.mytypesense.MainActivity.onCreate(MainActivity.kt:43)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3063)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:6729)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.osgi.framework.SynchronousBundleListener" on path: DexPathList[[zip file "/data/app/com.soho.mytypesense-6-OlfKw7m2tnLlbdQMGUMQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.soho.mytypesense-6-OlfKw7m2tnLlbdQMGUMQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at org.glassfish.jersey.internal.ServiceFinder.find(ServiceFinder.java:265) 
at org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:143) 
at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:509) 
at org.typesense.api.ApiCall.<init>(ApiCall.java:53) 
at org.typesense.api.Client.<init>(Client.java:27) 
at com.soho.mytypesense.MainActivity.callTypeSense(MainActivity.kt:55) 
at com.soho.mytypesense.MainActivity.onCreate(MainActivity.kt:43) 
at android.app.Activity.performCreate(Activity.java:7136) 
at android.app.Activity.performCreate(Activity.java:7127) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3063) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:198) 
at android.app.ActivityThread.main(ActivityThread.java:6729) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
build.gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.soho.mytypesense'
compileSdk 32
defaultConfig {
applicationId "com.soho.mytypesense"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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 {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.5.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
implementation files('libs/typesense-java-0.0.3.jar')
/*implementation ('org.glassfish.jersey.containers:jersey-container-servlet:2.25.1'){
exclude module : 'javax.inject'
}*/
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
And I've tried Jersey dependencies. But after that i got another compile issue as like this Duplicate class found
Duplicate class javassist.ByteArrayClassPath found in modules javassist-3.20.0-GA (org.javassist:javassist:3.20.0-GA) and typesense-java-0.0.3 (typesense-java-0.0.3.jar)
Duplicate class javassist.CannotCompileException found in modules javassist-3.20.0-GA (org.javassist:javassist:3.20.0-GA) and typesense-java-0.0.3 (typesense-java-0.0.3.jar)
Duplicate class javassist.ClassClassPath found in modules javassist-3.20.0-GA (org.javassist:javassist:3.20.0-GA) and typesense-java-0.0.3 (typesense-java-0.0.3.jar) many more...
Typesense Function
private fun callClient(){
CoroutineScope(Dispatchers.IO).launch {
try {
val nodes: ArrayList<Node> = ArrayList()
nodes.add(Node("https", "ts-cluster-staging....", "443"))
val configuration = Configuration(
nodes, Duration.ofSeconds(2), "FXOHZ..."
)
val client = Client(configuration)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
So how to fix this issue and dependency resolution errors?

AGP 7+ / JDK 11 / release: ClassNotFoundException: Didn't find class "okhttp3.MultipartBody$Part" on path: DexPathList

As the title says, I'm having some issue on a project since we updated to Java 11 and to AGP 7+.
The issue only happens in release and when we make a retrofit call using okhttp3.MultipartBody :
2022-01-18 00:56:23.043 27908-27908/com.test.okhttpissue E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test.okhttpissue, PID: 27908
java.lang.TypeNotPresentException: Type okhttp3.MultipartBody$Part not present
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:67)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76)
at libcore.reflect.GenericArrayTypeImpl.getGenericComponentType(GenericArrayTypeImpl.java:32)
at j2.y.j(:362)
at j2.s$a.j(:812)
at j2.s$a.g(:626)
at j2.s$a.f(:325)
at j2.s$a.b(:206)
at j2.s.b(:67)
at j2.v.b(:26)
at j2.u.c(:202)
at j2.u$a.invoke(:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy2.a(Unknown Source)
at f1.a.a(:41)
at com.test.okhttpissue.MainActivity.G(:30)
at com.test.okhttpissue.MainActivity.F(Unknown Source:0)
at f1.b.onClick(Unknown Source:0)
at android.view.View.performClick(View.java:7259)
at android.view.View.performClickInternal(View.java:7236)
at android.view.View.access$3600(View.java:801)
at android.view.View$PerformClick.run(View.java:27896)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.ClassNotFoundException: okhttp3.MultipartBody$Part
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:65)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76) 
at libcore.reflect.GenericArrayTypeImpl.getGenericComponentType(GenericArrayTypeImpl.java:32) 
at j2.y.j(:362) 
at j2.s$a.j(:812) 
at j2.s$a.g(:626) 
at j2.s$a.f(:325) 
at j2.s$a.b(:206) 
at j2.s.b(:67) 
at j2.v.b(:26) 
at j2.u.c(:202) 
at j2.u$a.invoke(:160) 
at java.lang.reflect.Proxy.invoke(Proxy.java:1006) 
at $Proxy2.a(Unknown Source) 
at f1.a.a(:41) 
at com.test.okhttpissue.MainActivity.G(:30) 
at com.test.okhttpissue.MainActivity.F(Unknown Source:0) 
at f1.b.onClick(Unknown Source:0) 
at android.view.View.performClick(View.java:7259) 
at android.view.View.performClickInternal(View.java:7236) 
at android.view.View.access$3600(View.java:801) 
at android.view.View$PerformClick.run(View.java:27896) 
at android.os.Handler.handleCallback(Handler.java:883) 
at android.os.Handler.dispatchMessage(Handler.java:100) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7397) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.MultipartBody$Part" on path: DexPathList[[zip file "/data/app/com.test.okhttpissue-pBclZ8Dcl_TuV_j7iAp7oA==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.okhttpissue-pBclZ8Dcl_TuV_j7iAp7oA==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:454) 
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:65) 
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76) 
at libcore.reflect.GenericArrayTypeImpl.getGenericComponentType(GenericArrayTypeImpl.java:32) 
at j2.y.j(:362) 
at j2.s$a.j(:812) 
at j2.s$a.g(:626) 
at j2.s$a.f(:325) 
at j2.s$a.b(:206) 
at j2.s.b(:67) 
at j2.v.b(:26) 
at j2.u.c(:202) 
at j2.u$a.invoke(:160) 
at java.lang.reflect.Proxy.invoke(Proxy.java:1006) 
at $Proxy2.a(Unknown Source) 
at f1.a.a(:41) 
at com.test.okhttpissue.MainActivity.G(:30) 
at com.test.okhttpissue.MainActivity.F(Unknown Source:0) 
at f1.b.onClick(Unknown Source:0) 
at android.view.View.performClick(View.java:7259) 
at android.view.View.performClickInternal(View.java:7236) 
at android.view.View.access$3600(View.java:801) 
at android.view.View$PerformClick.run(View.java:27896) 
at android.os.Handler.handleCallback(Handler.java:883) 
at android.os.Handler.dispatchMessage(Handler.java:100) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7397) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935) 
2022-01-18 00:56:23.074 27908-27908/com.test.okhttpissue I/Process: Sending signal. PID: 27908 SIG: 9
The problem does not occur on AGP 4.2.2 / Java 1.8.
I was able to reproduce it in a basic sample app with the following configuration :
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.test.okhttpissue"
minSdk 24
targetSdk 29
versionCode 1
versionName "1.0"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
signingConfig signingConfigs.debug
debuggable true
minifyEnabled true
shrinkResources true
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "io.reactivex.rxjava3:rxjava:3.1.3"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation "com.squareup.retrofit2:adapter-rxjava3:2.9.0"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
}
And the following snippet :
class IssueDemo {
val testApi: TestApi by lazy {
Retrofit.Builder()
.baseUrl("https://google.com")
.client(OkHttpClient().newBuilder().build())
.addCallAdapterFactory(RxJava3CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(TestApi::class.java)
}
interface TestApi {
#Multipart
#POST("test/files")
fun uploadMultipleFiles(#Part files: Array<MultipartBody.Part?>): Single<String>
}
fun execute() {
val file = File("")
val requestFile: RequestBody =
RequestBody.create(MediaType.parse("multipart/form-data"), file)
val test = MultipartBody.Part.createFormData("nameFormData", file.name, requestFile)
testApi.uploadMultipleFiles(arrayOf(test))
}
}
I tried many things but so far the only thing that seems to fix it is to add a proguard rule -keep class okhttp3.MultipartBody but it doesn't feel right. With AGP 4.2.2 it was already using R8 and the proguard rules bundled with the library so why would we suddendly need another specific rule just for one class of this library?
Edit: It seems that switching from Array<MultipartBody.Part?> to List<MultipartBody.Part?>, without touching any proguard rule, solves the issue. Does someone understand what could be happening?
Possible that R8 can't detect the class being used as it may be invoked by reflection. If that is the case, you have to add explicit keep rule in proguard-project.txt.

The following classes could not be instantiated:- android.support.design.widget.NavigationView

I'm trying to use this https://github.com/Siclo-Mobile/EZPhotoPicker in my app.
I had my build.gradle (inside "app" folder) looking like this before the implementation (And the app working fine):
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
signingConfigs {
vitalRelease {
keyAlias 'XXXX'
keyPassword 'XXXXX'
storeFile file('XXXXXXXXXXX')
storePassword 'XXXXXXX'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.enye.cme"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:1.7.2'
compile 'com.splitwise:tokenautocomplete:2.0.2#aar'
compile 'com.github.citux:datetimepicker:0.2.0'
compile 'com.prolificinteractive:material-calendarview:1.1.0'
//compile 'com.nbsp:library:1.08'
compile 'com.github.siyamed:android-shape-imageview:0.9.+#aar'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.4#aar'
compile 'com.google.android.gms:play-services-ads:9.0.0'
compile('com.crashlytics.sdk.android:answers:1.3.6#aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.2#aar') {
transitive = true;
}
compile 'com.nononsenseapps:filepicker:2.5.2'
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.google.android.gms:play-services-appindexing:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
I followed the instructions given there in the README.md in the GitHub, and now my build.gradle looks like this:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://dl.bintray.com/siclo/SicloAndroidOSS' } //ADDED THIS LINE
}
android {
signingConfigs {
vitalRelease {
keyAlias 'XXXXX'
keyPassword 'XXXXXX'
storeFile file('XXXXXXXXXXX')
storePassword 'XXXXXX'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.enye.cme"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.vitalRelease
}
}
productFlavors {
vital {
applicationId "com.enye.mce"
buildConfigField 'String', 'appId', '"MCE"';
}
cuidam {
applicationId "com.enye.cuidam"
buildConfigField 'String', 'appId', '"CUIDAM"';
}
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:1.7.2'
compile 'com.splitwise:tokenautocomplete:2.0.2#aar'
compile 'com.github.citux:datetimepicker:0.2.0'
compile 'com.prolificinteractive:material-calendarview:1.1.0'
//compile 'com.nbsp:library:1.08'
compile 'com.github.siyamed:android-shape-imageview:0.9.+#aar'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.4#aar'
compile 'com.google.android.gms:play-services-ads:9.0.0'
compile('com.crashlytics.sdk.android:answers:1.3.6#aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.2#aar') {
transitive = true;
}
compile 'com.nononsenseapps:filepicker:2.5.2'
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.google.android.gms:play-services-appindexing:9.0.0'
compile 'com.siclo.ezphotopick:library:1.0.1' //ADDED THIS LINE
}
apply plugin: 'com.google.gms.google-services'
As you can see, I didn't change anything but those 2 lines that are given in the instructions.
Now when I start the app it crashes and throws me this error:
01-18 18:51:22.096 9036-9036/com.enye.cuidam E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.enye.cuidam, PID: 9036
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.enye.cuidam/com.enye.cme.activities.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.enye.cme.activities.MainActivity.onCreate(MainActivity.java:117)
at android.app.Activity.performCreate(Activity.java:6245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.enye.cme.activities.MainActivity.onCreate(MainActivity.java:117)
at android.app.Activity.performCreate(Activity.java:6245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.enye.cme.activities.MainActivity.onCreate(MainActivity.java:117)
at android.app.Activity.performCreate(Activity.java:6245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NoClassDefFoundError: android.support.design.internal.NavigationMenuPresenter
at android.support.design.widget.NavigationView.<init>(NavigationView.java:80)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:92)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.enye.cme.activities.MainActivity.onCreate(MainActivity.java:117)
at android.app.Activity.performCreate(Activity.java:6245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
The #117 line of MainActivity is this one:
setContentView(R.layout.activity_main);
And this is the layout activity_main:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">
<include layout="#layout/app_bar_main" android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView android:id="#+id/nav_view"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:fitsSystemWindows="true"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Am I doing something wrong? It doesn't even inflate the activity, I guess I messed up the build.gradle.
Thanks in advance for your help!

Crash app when using AndroidAnnotations with support:appcompat-v7 version 23 +

I'm using lastest AndroidAnnotations 4.1.0(link) and try to change appcompat to 24.2.1 to support targetVersion 24. But, My app is crashed when using appcompat-v7 version 23+, however, it runs normally on appcompat-v7:22.2.0. Any suggestion is appriciated. Below is my error logs:
FATAL EXCEPTION: main
Process: ABC, PID: 1275
java.lang.RuntimeException: Unable to start activity ComponentInfo{MyPackage/MyPackage.activities.MainActivity_}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5137)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at MyPackage.activities.MainActivity_.setContentView(MainActivity_.java:51)
at MyPackage.activities.MainActivity_.onCreate(MainActivity_.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286) 
at android.app.ActivityThread.access$800(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:212) 
at android.app.ActivityThread.main(ActivityThread.java:5137) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Must specify unique android:id, android:tag, or have a parent with an id for MyPackage.fragments.MainFragment_
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2387)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:376)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at MyPackage.activities.MainActivity_.setContentView(MainActivity_.java:51) 
at MyPackage.activities.MainActivity_.onCreate(MainActivity_.java:40) 
at android.app.Activity.performCreate(Activity.java:5231) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286) 
at android.app.ActivityThread.access$800(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:212) 
at android.app.ActivityThread.main(ActivityThread.java:5137) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718) 
at dalvik.system.NativeStart.main(Native Method) 
And this is my gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
...
def PACKAGE_NAME = "MyPackage"
def VERSION_CODE = 1
def VERSION_NAME = "1.0.0"
def AAVersion = '4.1.0'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
buildscript {
repositories {
mavenCentral()
...
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:2.2.0'
// replace with the current version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
...
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName PACKAGE_NAME
}
}
repositories {
mavenCentral()
...
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId PACKAGE_NAME
minSdkVersion 14
targetSdkVersion 24
versionCode VERSION_CODE
versionName VERSION_NAME
// Enabling multidex support.
multiDexEnabled true
}
signingConfigs {
...
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
...
}
dexOptions {
...
}
...
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
...
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-maps:9.6.1'
compile 'com.google.android.gms:play-services-location:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
compile('com.squareup.okhttp3:okhttp:3.2.0') {
exclude module: 'okhttp'
}
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.github.mrmike:ok2curl:0.2.3'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.android.support:multidex:1.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2#aar') {
transitive = true;
}
}
repositories {
flatDir {
dirs 'libs'
}
}
As it is an be ready from the stack trace, the problem is that you did not add any ID neither a tag for your Fragment in the xml layout where you declare an instance if it. The Fragment in question is MyPackage.fragments.MainFragment_. This is a standard error, not related to AndroidAnnotations.
<fragment android:name="MyPackage.fragments.MainFragment_"
android:id="#+id/fragment_id" <!-- Add an ID -->
android:layout_width="match_parent"
android:layout_height="match_parent" />

Facebook login button on Android causing ExceptionInInitializerError

I am using Facebook's Android SDK. If I add Facebook's LoginButton to my xml layout. I receive a runtime error: ExceptionInInitializerError.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
</RelativeLayout>
My MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
}
Here is the stack trace:
java.lang.ExceptionInInitializerError
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at android.app.Activity.setContentView(Activity.java:2145)
at com.dupls.wedding.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: null
at com.facebook.internal.Validate.sdkInitialized(Validate.java:99)
at com.facebook.FacebookSdk.getCallbackRequestCodeOffset(FacebookSdk.java:735)
at com.facebook.internal.CallbackManagerImpl$RequestCodeOffset.toRequestCode(CallbackManagerImpl.java:109)
at com.facebook.login.widget.LoginButton.<clinit>(LoginButton.java:58)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
            at android.app.Activity.setContentView(Activity.java:2145)
            at com.dupls.wedding.MainActivity.onCreate(MainActivity.java:25)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
build.gradle (Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.dupls.wedding"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
}
build.gradle (Project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
I haven't been able to find any determine what the cause of this Exception is. I can instantiate the Facebook SDK objects, I just can't seem to add a LoginButton to my UI. Any ideas? Thanks.
public void onCreate(final Bundle savedInstanceSate) {
super.onCreate(savedInstanceSate);
**FacebookSdk.sdkInitialize(this.getApplicationContext());**
setContentView(R.layout.activity_main);
}
Initialize FacebookSdk before setContentView in your class.
FacebookSdk.sdkInitialize(this.getApplicationContext());
put this line before the setContentView
Check the sizes of the libraries in the place you built and the path you copied to.Sometimes when the library is partially copied,this error occurs.
Had the exact same issue. I fixed it by adding the meta-data to the manifest and the FacebookActivity as described in the following link:
https://developers.facebook.com/docs/android/getting-started#login_share
Ensure that you follow all the pre-requisite steps outlined in this Facebook documentation:
https://developers.facebook.com/docs/facebook-login/android
And then add
FacebookSdk.sdkInitialize(this)
before setContentView
Remove mavenCentral() from repositories node in build.gradle (Project) and add it in build.gradle (Module: app) like
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
repositories {
mavenCentral()
}
defaultConfig {
applicationId "com.ehapi.rentapp"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
}

Categories

Resources