I read many discussions about this topic but no any an exact answer I found. One says you should use Android Studio instead of Eclipse because it supports Gradle and uses Maven building. But I develop games in Eclipse using libGDX and it supports Gradle and Maven building too. Another says you should add multidex.jar from your path SDK tools or from Gradle then enable it inside gradle then extends MultiDexApplication instead of Application then install it inside attachBaseContext method. Nice, but it doesn't work.
And how can I extend MultiDexApplication instead of AndroidApplication?.
Does libGDX has modification class on Application like AndroidApplication but in MultiDexAndroidApplication case?
Another says you shoud convert your project into Maven project or add some lines in pom.xml file to build many dex files!!.
I read more about this topic, but no any answer of their answers solve this problem (In libGDX using Eclipse case).
Any help!!
You can set multi dex enabled in Gradle (android/build.gradle) like so:
android {
buildToolsVersion "23.0.2"
compileSdkVersion 23
defaultConfig {
multiDexEnabled = true
applicationId = package_name
}
dexOptions {
javaMaxHeapSize "4g"
}
lintOptions {
disable 'ExportedContentProvider', 'IconColors'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
}
I believe the only lines you need to add are:
defaultConfig {
multiDexEnabled = true
applicationId = <your_package_name>
}
Related
I am trying to integrate openCV in Android studio for my latest project. I followed the following steps:
Imported new module ..\OpenCV-android-sdk\java\
Added dependancy OpenCVLibrary320
Changed compilesdk and targetsdk versions to 23 and buildToolsVersion to 25.0.0 in the build.gradle of OpenCVLibrary320
Copied the contents of ..\OpenCV-android-sdk\sdk\native to app\main\src\jniLibs (After creating a jni folder)
Wrote a snippet of code to test if it was working
But I got the error:
Error:Execution failed for task ':app:compileDebugNdk'.
Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
https://developer.android.com/studio/build/experimental-plugin.html.
How can I fix this problem?
Note: In step 4, I created the jniLibs folder but it did not show up in the 'Android' view so I had to copy the contents to the jniLibs folder in the 'Project' view.
In gradle add module dependency:
include ':libraries:opencv'
add in build.gradle with this content
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0.0"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
Manualy add the jar file in the lib folder,
app -> libs -> xyz.jar
This will also create duplicate jar issue, remove from the previous folder, because it gets compiled twice if you do not remove
I searched and I could not find the answer to my problem. There was a solution that seemed valid, but could not use it in AS 2.1.1 (latest) - Product flavour [Migrating from eclipse to android studio]
My issue is as follows:
A senior dev started a project in Eclipse, the project has grown a lot and now he left. I have to migrate the project in AS to be able to add new stuff and this killed.
I started with going into Eclipse and Exporting the project for Gradle. I went into AS and imported the project.
All seems well so far, but now comes the fun part: the project was building on a separate machine, using different configs for each flavor. In AS I was not able to do so. I will attach here my config maybe someone can help. I need each flavor with a different assets folder that will contain the config file, and a different manifest, as each version can have different names / strings. The rest of the code should be common so it can be easily modified for all version.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
productFlavors {
v1 {
//manifest.srcFile 'src/v1/AndroidManifest.xml'
//assets.srcDirs = ['src/v1/assets']
}
v2 {
//manifest.srcFile 'src/v2/AndroidManifest.xml'
//assets.srcDirs = ['src/v2/assets']
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
v1 {
manifest.srcFile 'src/v1/AndroidManifest.xml'
assets.srcDirs = ['src/v1/assets']
}
v2 {
manifest.srcFile 'src/v2/AndroidManifest.xml'
assets.srcDirs = ['src/v2/assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
I'm trying to add this libraries to my project:
com.loopj.android:android-async-http:1.4.6
com.google.apis:google-api-services-analytics:v3-rev115-1.20.0
com.github.castorflex.smoothprogressbar:library:1.1.0
But Android Studio is returning this errors:
Error:(8, 13) Failed to resolve:
com.github.castorflex.smoothprogressbar:library:1.1.0
Error:(6, 13) Failed to resolve:
com.loopj.android:android-async-http:1.4.6
Error:(7, 13) Failed to resolve:
com.google.apis:google-api-services-analytics:v3-rev115-1.20.0
This is my build.grade file:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':librarySmartHotel')
compile 'com.loopj.android:android-async-http:1.4.6'
compile 'com.google.apis:google-api-services-analytics:v3-rev115-1.20.0'
compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
compile 'com.google.android.gms:play-services:6.5.87'
}
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Do I have to configure something?? for example com.google.android.gms:play-services:6.5.87 is working perfect and I have not done any configuration.
Any help will be appreciated.
Firstly try to add to your Project build.gradle file following code or just add it to existent repositories
repositories {
mavenCentral()
}
Also you may have "Offline mode" enabled. Check if File -> Build,Execution,Deployment-> Maven/Gradle "Offline work" is enabled, if so just disable it and Sync Gradle
And let me know results.
The Gradle builds which you mentioned perfectly compiled with mine. I suggest you to clean your project and restart android studio and try once again. Please let us know if the problem persists.
I am following the instructions here, however I am running into problems at step 3 "Import the SDK into an Android Studio Project". I imported the Module and set to compile as specified however, when I try to modify the settings.gradle I am running into problems. It keeps giving me Gradle 'MyApplicationProject' project refresh failed: You are using an old, unsupported version of Gradle please use 1.6 or higher. I am build the app with version 4.3 compiler while supporting all the way to 4.0(Android).
This is my settings.gradle
include ':MyPeeps'
include ':libraries:facebook', ':MyApplicationProject'
after is wasn't auto populating I added
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':libraries:facebook')
}
Also put this into the build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
When I go to put in the onCreation command for facebook errors with all the commands that use the facebook api. Does anyone know how I can fix my gradle issues?
Change 'com.android.tools.build:gradle:0.4' to 'com.android.tools.build:gradle:0.5.+'
I decided to drop android studio and just go back to adt plugin got it work quickly at that point. Thanks for the help.
I had a gradle error at first where I needed to change the version. I read about this problem on the android studio website, and I followed there directions and changed this line in the gradle file:
classpath 'com.android.tools.build:gradle:0.5.0'
My error didnt go away and my main was full of red underlines. I then restarted Android Studio and everything seemed fixed.
But when I tried to compile and run on my phone from my mac book air I got this error:
Gradle: A problem occurred evaluating root project 'BeerPortfolioPro'.
> The SDK directory '/Users/Mike/Library/Caches/AndroidStudioPreview/compile-server/"/Applications/Android Studio.app/sdk"' does not exist.
my gradle build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.0'
}
}
apply plugin: 'android'
dependencies {
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
You can change the dependency to 'com.android.tools.build:gradle:0.5.4'.
Also, add a local.properties file in the project root folder with a line pointing to the Android Studio sdk directory. I had to put this line:
sdk.dir=/Applications/Android Studio.app/sdk