NoClassDefFoundError with Android Studio on Android 4 - android

I'm in the process of converting an existing app from Eclipse to Android Studio. However, when I run it on a device running 4.x (I've tested several versions on emulators), it immediately crashes with a NoClassDefFoundError.
I've tried commenting out references to the classes it can't find, but there's always another. As far as can tell, the offending class is always
Within my own code
An inner class (Update: With more investigation, this one isn't always true)
Everything works fine on a 5.0.1 emulator (I don't have a device to test on). My build.gradle file is fairly long, but looks like this:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = "2.7.1"
android {
compileSdkVersion 19
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.myapp.android"
minSdkVersion 8
targetSdkVersion 19
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
*snip*
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.pact.android'
}
}
dependencies {
*snip compile project(':...') declarations
apt "com.googlecode.androidannotations:androidannotations:$AAVersion"
compile "com.googlecode.androidannotations:androidannotations-api:$AAVersion"
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:3.1.36'
*snip many more compile declarations*
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Some examples of classes that cause trouble:
An anonymous class that implements an interface inside the facebook library (as a library project)
Parcelable.CREATOR implementations in my models
An inner class that extends android.os.Library
An inner class in my own code
A class that implements an interface in a library from maven
What's going wrong, and how do I fix it?

I was incompletely implementing MultiDex support, so some of my classes weren't in the proper dex file. To fix it, you have to do more than just set multiDexEnabled = true in your defaultConfig block. You also have to:
Include compile 'com.android.support:multidex:1.0.1' in your dependencies
Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application.
See https://developer.android.com/tools/building/multidex.html for more details.

1) Add multiDexEnabled = true in your default Config
2) Add compile com.android.support:multidex:1.0.0 in your dependencies
3) Application class extend MultiDexApplication instead of just Application

1) add multiDexEnabled = true in your defaultConfig in build.gradle.
2) You also have to Include compile 'com.android.support:multidex:1.0.1'
3) add the following to your "application" tag in your manifest:
android:name="android.support.multidex.MultiDexApplication"
its working with me , hope that help

I solved the problem by removing multiDexEnabled = true in my case.

I also issue get resolved after doing following steps
1) add multiDexEnabled = true in your defaultConfig in build.gradle.
2) You also have to Include compile com.android.support:multidex:1.0.1
3) add the following to your "application" tag in your manifest:
android:name="android.support.multidex.MultiDexApplication"

I got the same issue, tried all solutions suggested on StackOverflow but they did not work in my case.
After that I found out that one of libraries compiled by Java 8. So, I need to enable Java 8 in my project too.
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
There are many reasons which leads to this error. Hope it helps.

In my case, it was Kotlin forEach was causing the exception.
More info here: java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1 in Kotlin

Related

Lint found fatal errors while assembling a release target - gradle error?

I am using AS 3.1 with gradle-4.5-all.zip and main build.gradle:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
An app-level build.gradle looks like following:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 27
versionCode 6
versionName "1.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation 'ch.acra:acra:4.6.1'
implementation 'commons-validator:commons-validator:1.5.0'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.google.zxing:core:3.3.0'
}
and works fine when I set up a debug version under AS 3.1 to my phone, but when I try to make release apk it shows me an error:
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build
script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
As I can see in the lint-results-release-fatal.html the reason is:
I would not like to change lintOptions to supress this error because it doesn't solve the problem, it just hide it. More over, when I use
implementation files('libs/commons-validator-1.5.0.jar')
instead of
implementation 'commons-validator:commons-validator:1.5.0'
the release apk is compiled without any error messages. Is it a some gradle bug or what!?
P.S. I have attached a file androidDependencies.txt. Package commons-logging doesn't appears in the dependencies at all! How is it possible to get the solution of above problem analysing this file?
the release apk is compiled without any error messages. Is it a some
gradle bug or what!?
It seems like that dependency has a package which conflicts with the Android itself. The reason why it works without implementation and adding it manually, it might be that it downloads needed packages when you add it to be downloaded from maven repository and that's when the issue came up.
Anyways, the solution at these situations might be using the latest version:
implementation 'commons-validator:commons-validator:1.6'
Or, exclude it as follows:
implementation ('commons-validator:commons-validator:1.5.0') {
exclude group: 'commons-logging', module: 'commons-logging'
}
Note: The following part can't be helpful (for this issue) since the error says:
Commons-logging defines classes that conflict with classes now
provided by Android
You could go deeply by running ./gradlew app:dependencies in the IDE terminal to see which one conflicts with the Android itself and then excluding it as above.

MultiDexApplication not found at app launch [duplicate]

I'm trying the new MultiDex Support on my app and so far I've managed to compile my app correctly, but when running it, I get the following exception:
java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/me.myapp.main-2.apk"],nativeLibraryDirectories=[/data/app-lib/me..main-2, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/me.myapp.main-2.apk"],nativeLibraryDirectories=[/data/app-lib/me.myapp.main-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:998)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
This is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
}
And my AndroidManifest.xml:
<application
android:name="android.support.multidex.MultiDexApplication">
I don't understand what the problem is. I think I'm doing everything according to the documentation. Is there something else i am missing? I made sure I had the latest support library and repo installed from the SDK manager.
The solution didn't help me because I was using jetpack version ie androidx. libraries.
Followed official doc.
And
I had to change name to androidx....Multidex.
<application
android:name="androidx.multidex.MultiDexApplication" >
...
</application>
Hope It helps other people looking for adding multidex with jetpack.
In my case its solved by changes below code in Manifest from
android:name="android.support.multidex.MultiDexApplication"
to
android:name="androidx.multidex.MultiDexApplication"
My configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.+' // 0.14.1, 2014-11-6
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
android {
compileSdkVersion = 21
buildToolsVersion = "21.1.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled true
}
}
Unfortunately, I have the same problem. But I found a strange situation:
build/intermediates/dex/debug:
-rw-rw-r-- 1 andrew andrew 2221176 Nov 6 20:18 classes2.dex
-rw-rw-r-- 1 andrew andrew 8357596 Nov 6 20:18 classes.dex
unzip apk, build/outputs/apk:
-rw-rw-r-- 1 andrew andrew 8357596 Nov 6 20:18 classes2.dex
-rw-rw-r-- 1 andrew andrew 2221176 Nov 6 20:18 classes.dex
In apk, the main classes of classes.dex should be bigger than classes2.dex, but its not. I do also dex2jar & unzip jar to check classes, the application class is not there in classes.dex, its in classes2.dex contrarily.
However, I should have fixed it. Here is my patched android gradle plugin you can try:
buildscript {
repositories {
mavenCentral()
maven { url 'https://github.com/yongjhih/android-gradle-plugin.m2/raw/master/' }
}
dependencies {
classpath 'com.infstory.tools.build:gradle:0.14.+'
}
}
The patch is in: https://github.com/yongjhih/android-gradle-plugin/commit/9c2212e3b1b4c6e1f7b47f2086aba1903a6258bf
or
https://android-review.googlesource.com/#/c/113331/
issue: https://code.google.com/p/android/issues/detail?id=78761
The official patch is https://android-review.googlesource.com/#/c/113201/ that already been merged, I think it might be fixed in next version.
Already been fixed 0.14.2 (2014/11/10). (from http://tools.android.com/tech-docs/new-build-system)
Release notes:
0.14.2 (2014/11/10)
Fix potential multi-dex issue where the dex files could be renamed during packaging, leading to the wrong main dex file being used.
Fix versionNameSuffix support
Fix BuildType.initWith to copy shrinkResources flag
setup default proguard rule file if none are provided (SDK/tools/proguard/proguard-android.txt)
BuildType.pseudoLocalesEnabled flag to include fake locales in apk.
Setting up your app project to use a multidex configuration requires that you make the following modifications to your app project, depending on the minimum Android version your app supports.
If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
...
}
However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:
Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Depending on whether you override the Application class, perform one of the following:
If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
I recently had this issue. Despite no change to my configuration this error started occurring. I tried all of the suggested solutions including deleting the virtual device and creating a fresh one.
However, I did notice that if I built an APK and dragged it into the emulator to install, it worked fine.
In the end cleaning the project and re-running and then it worked.
For me, the answer was to switch to the androidx versions
android:name="androidx.multidex.MultiDexApplication"
implementation "androidx.multidex:multidex:2.0.1"
I was using the latest Android Studio and following the official document to add support to multidex https://developer.android.com/studio/build/multidex.html . But I still got the same exception. I spent a lot of time solving it. At last, I found the cause was I enabled "Java Exception Breakpoints - Any exception", and "Exception Breakpoints - When any is thrown". After I disabled them, the app ran without problems.
Just follow the official document about multidex https://developer.android.com/studio/build/multidex.html . It works.
Delete ./gradle .idea and build directory
Clean project
Uninstall app if already install on device and again install
In my case I just changed the build.gradle and I leaved the AndroidManifest like that:
android:name=".MainApplication"
I am using React Native.
i jaust changed
in manifest application
android:name="android.support.multidex.MultiDexApplication"
to
android:name="androidx.multidex.MultiDexApplication"
and it's working fine
This worked for me.
File -> Sync Project with Grandle Files
Very strange, I got same error message, but after I fixed some gradle lines it worked. Maybe it helps somebody:
Project build.gradle:
from:
..
dependencies {
// Android Gradle Plugin
classpath 'com.android.tools.build:gradle:3.2.1'
// Analytics
**classpath 'com.google.gms:google-services:3.0.0'**
}
..
to:
..
dependencies {
// Android Gradle Plugin
classpath 'com.android.tools.build:gradle:3.2.1'
// Analytics
**classpath 'com.google.gms:google-services:3.2.1'**
}
..
In the module build.gradle:
from:
..
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
**implementation 'com.google.android.gms:play-services-analytics:12.0.1'**
}
..
to:
..
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
**implementation 'com.google.android.gms:play-services-analytics:16.0.5'**
}
..
There was no other changes in my code, but the fixed version worked on 4.x emulators too. Only the ** marked lines are changed.
The Problem is in Gradle File Please Increase the Version That's it
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.nandeproduction.dailycost"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}}
[Solution] Use this special code
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
Go to manifest -> inside application tag -> directly put your class name with dot or check the package of that file and add that manually.
android:name=".AppController"

Toolbar: IllegalStateException - configure your build for VectorDrawableCompat

I'm using Android Studio 2.1.2. I started a new project with minSdkVersion as 19. My activity extends AppCompatActivity. The project starts with an empty activity using a fragment.
When previewing content_main.xml with API 24, all is good. when previewing API 19, I get the following rendering problem:
The following classes could not be instantiated:
- android.support.v7.widget.Toolbar
java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat
I have added every thing I found relevant to the gradle (2 files):
classpath 'com.android.tools.build:gradle:2.1.2'
vectorDrawables.useSupportLibrary = true
buildToolsVersion "24.0.1"
compile 'com.android.support:appcompat-v7:24.1.1'
compile "com.android.support:support-v4:24.1.1"
compile 'com.android.support:design:24.1.1
But still the error appears. I've found a lot of answers on internet. But none helped. Is there a problem using the new toolbar with API 19?
This worked well for me
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
generatedDensities = []
}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Notice this in the above code:
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
and
generatedDensities = []
from this google Issue
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
check this issue for more help.
UPDATE
configured your app build.gradle file as follows
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
}
Source
Age Of Vectors
Firstly, there are two types of gradle files.
build.gradle(Project: ProjectName)
build.gradle(Module: app)
For more information on these two files, go through this answer.
Coming to your question,
I've found a lot of answers on the net but none helped. I'm using
Android Studio 2.1.2, my activity extends AppCompatActivity and added
to the gradle (2 files) every thing I found relevant: but still the
error appears.
From whatever you have posted, it seems like you didn't add right things at right places.
You shouldn't place your application dependencies in build.gradle(Project: ProjectName) - Android Studio says,
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Hence, replace your dependencies in build.gradle(Project: ProjectName) with below
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
Replace your dependencies in build.gradle(Module: app) with below
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
}
After doing as mentioned above, you will see a "Sync Now" option on the Top Right. Click it. Android Studio will take care of remaining things.
Also this question similar is to yours. Go through it. It may help.
Add :
build.gradle
defaultConfig {
...
vectorDrawables.useSupportLibrary = true
...
}
And on top of your Activity class:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
And one last thing put your vector drawables inside any other drawables like selector, LayerList, etc. Something like below:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drawable_vector" />
</selector>
And use this above drawable everywhere instead of setting vector drawables directly. This will at other places as well whenever you want to use vector drawables on pre-lollipop devices.

Share external dependencies between modules in Android Studio

I'm trying to share 2 external dependencies between 2 modules in Android Studio.
The 2 dependencies are Twitter Core and Twitter4j (a Twitter library extension I'm experimenting with).
Here is the project structure:
Root project 'cineios-test'
+--- Project ':app'
\--- Project ':cineio-broadcast-android-sdk'
I set up the dependencies in my app build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.lgorse.cineios_test"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':cineio-broadcast-android-sdk')
//compile project(':cineio-broadcast-android')
//compile 'io.cine:cineio-broadcast-android-sdk:0.0.9'
compile ('org.twitter4j:twitter4j-stream:4.0.2'){
transitive = true;
}
compile('com.twitter.sdk.android:twitter:1.1.1#aar') {
transitive = true;
}
}
Here is the build.gradle file for the module, which is cineios-android-sdk:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
// applicationId 'io.cine.android'
minSdkVersion 18
targetSdkVersion 19
versionCode 11
versionName '0.0.11'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile 'com.google.guava:guava:16.0'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
}
Finally here is settings.gradle:
include ':app', ':cineio-broadcast-android-sdk'
project(':cineio-broadcast-android-sdk').projectDir = new File('cineio-broadcast-android/cineio-broadcast-android-sdk')
I know there are answers on SO but they refer adding local libraries as modules - but since these dependencies are remote I'm not sure how to adapt the hints to this situation.
I did try adding the dependencies to the other module (cineios-android) but a) it seems ridiculous to double them up like that and b)that would imply registering a new app in the Twitter API, which will probably lead to errors.
The correct approach really is to specify the dependencies in both the main app and the module.
I did try adding the dependencies to the other module (cineios-android) but a) it seems ridiculous to double them up like that and
There's really nothing ridiculous about it. Don't think of it as trying to "share" the dependency between the main app and the module. Look at it this way: your module depends on Twitter4j and Twitter Core. If you were to reuse that module in a different application, the module should be self-contained and should be able to specify its own dependencies without the parent project needing to set them up. Making all its dependencies explicit does this.
If the parent app also depends on Twitter4j and Twitter Core, and if you use the Maven Coordinate-style remote dependency specs as you have, the build system will ensure that only one copy actually gets linked into the app, so everything will be okay.
b)that would imply registering a new app in the Twitter API, which will probably lead to errors.
I'm not familiar with how that works, so I can't comment on it other than to say that if their API is well designed, hopefully just including the library shouldn't imply something like that. If you're having problems, clarify your question or ask a new one.
In your build.gradle add dependency like below:
dependencies {
compile 'org.openimaj:twitter:1.3.1'
}
You can also use belowed link for more reference :
Gradle Please

MultiDexApplication not recognized

Trying to use MultiDexApplication in my app, but the class is not recognized when I try to extend my application activity with it.
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
defaultConfig {
applicationId 'com.myapp'
minSdkVersion 10
targetSdkVersion 21
versionCode 115
versionName '4.8'
}
buildTypes {
debug {
debuggable true
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
debuggable false
runProguard true
zipAlign true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
checkReleaseBuilds false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile project(':facebook')
}
You can see that I'm compiling on 21, using the latest build tools, and the latest google play services and support library.
Has anyone gotten this to work?
MultiDexApplication class is not part of appcompat-v7 library. It is being shipped in a separate jar (called android-support-multidex).
Find the android-support-multidex.jar under /sdk/extras/android/support/multidex/library/libs (available from revision 21 of support library) and copy it to your project's libs folder.
Update (11/5/2014):
The jar is now available in central repository:
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
}
For more info, see here.
Update (27/9/2021):
Jetpack (AndroidX) users should add this as a dependency:
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1'
}
Although this question is quite old, I got this error in a multi-module setup when trying to build the different modules together as one APK for API < 21. I already refactored to AndroidX, but the multidex docs don't mention AndroidX yet.
If you are using AndroidX, make sure to replace the old multidex dependency
compile 'com.android.support:multidex:1.0.3'
with the new one
implementation 'androidx.multidex:multidex:2.0.0'
I have followed THIS blog post according to which MultiDexApplication should be included in r21 of support library.
My IDE had trouble resolving it also.
I made it work for now with the help of MULTIDEX github project by adding (you can see more details on the project's page):
android {
dexOptions {
preDexLibraries = false
}
}
repositories {
jcenter()
}
dependencies {
compile 'com.google.android:multidex:0.1'
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex' // enable multidex
dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
}
}
and adding $project_dir/multidex.keep file with following contents:
android/support/multidex/BuildConfig.class
android/support/multidex/MultiDex$V14.class
android/support/multidex/MultiDex$V19.class
android/support/multidex/MultiDex$V4.class
android/support/multidex/MultiDex.class
android/support/multidex/MultiDexApplication.class
android/support/multidex/MultiDexExtractor$1.class
android/support/multidex/MultiDexExtractor.class
android/support/multidex/ZipUtil$CentralDirectory.class
android/support/multidex/ZipUtil.class
The github project page mentions also some consideration for the contents of your implementation of MultiDexApplication class:
The static fields in your application class will be loaded before the
MultiDex#installbe called! So the suggestion is to avoid static fields
with types that can be placed out of main classes.dex file.
The methods of your application class may not have access to other classes
that are loaded after your application class. As workarround for this,
you can create another class (any class, in the example above, I use
Runnable) and execute the method content inside it.
I got the solution :)
Upgrade to jdk 8 and change JDK location in Android Studio in
File > Project Structure > SDK Location
Find and change JDK location and click OK

Categories

Resources