transferred computers with Android Studio and now have Gradle error - java

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

Related

Unable to integrate OpenCV in android studio

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

Migrate from Eclipse to Android Studio

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')
}
}

How can I use MultiDexApplication in libGDX for Android

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>
}

Unable to sync Android Studio with Maven repository

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.

How to properly import Android projects in Android studio?

I have been fighting with Android Studio for 2 dayys because I cannot import 2 eclipse projects in the IDE.Here what I have done.
The projects are 2 Eclipse projects and I export them by doing FILE > EXPORT > Generate build.gradle files.
When I try to import the projects in Android Studio, I have this error :
Failed to refresh Gradle project 'SourceFiles'
You are using Gradle version 1.11, which is not supported. Please use version 1.9.
Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)
Fix Gradle wrapper and re-import project Gradle settings
As you see I use the latest distribution of gradle (version 1.11) and it still does not work.
Can someone show me the proper way to import those projects in Android Studio?
I am on
Linux OpenSuse version 13.1
Android Studio : 0.4.2
Java : 1.7
[EDIT] My project is comprised of directory Sourcefiles which contains 2 sub-directories Skeletons and Testcase. Skeletons contains the source files and TestCase contains the test case associated with the project in Skeletons.
Here are the build.gradle generated by Eclipse :
In SourceFiles level :
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
In the Skeletons level :
android {
compileSdkVersion 18
buildToolsVersion "19.0.2"
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')
}
}
In the testcase level directory :
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':Skeletons:FragmentsLab')
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.2"
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')
}
}
I also have to admit that I am still a noob in gradle.
I also updated the Android Studio the latest version in the canary channel and references the verison 1.9 of gradle in my project.
Any help would be appreciated.
I would want to use the Eclipse IDE but it keeps crashing.
Latest gradle versions have many issues, you should really try to use an older one, 1.9 is fine. Add this to the root build.gradle and run gradle wrapper from console:
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
It should create a gradle path in your project. After that, use gradlew instead of gradle in command line or pick a "customizable gradle wrapper" option when creating a project in Android Studio.
If you'll encounter further issues with versions change the value of distributionUrl in gradle\wrapper\gradle-wrapper.properties

Categories

Resources