I have pretty large source tree which includes JNI sources as well:
android {
compileSdkVersion 19
buildToolsVersion '21.1.1'
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
aidl.srcDirs=['src/main/aidl']
assets.srcDirs = ['src/main/assets']
jni.srcDirs=[] //to suppress makefiles autogeneration
//jni.srcDirs=['src/main/jni']
jniLibs.srcDirs=['src/main/libs'] //native *.so in armeabi x86 and mips to include
}
}
}
//skipped
dependencies {
apt 'org.androidannotations:androidannotations:3.0+'
compile 'org.androidannotations:androidannotations-api:3.0+'
compile project(':actionbarsherlock')
compile project(':actionbarsherlocki18n')
compile 'com.android.support:support-v4:21.0.2'
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/acra-4.5.0.jar')
compile files('libs/libphonenumber-5.9.jar')
compile files('libs/universal-image-loader-1.8.6.jar')
}
ant.importBuild 'src/main/jni/build_native.xml' //ant task to build JNI
Everything works except Gradle doesn't put *.so files into final APK file. Ant really generates *.so libraries and put them into src/main/libs/x86 and src/main/libs/armeabi folders - I have double checked it.
I'm really stuck with this issue - please help.
BTW: Merry X-Mas!
Key point in my case was:
compileSdkVersion 21 //instead 19
As soon as I have changed compileSdkVersion from 19 to 21 - problem was resolved (required also to change JDK 6 to JDK 7.
Magic...
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 have strange problem and don't know how to resolve it.
I have an interface with default method, like this:
public interface ITest{
default String getText(){
return "ITest";
}
}
and class which implements this interface, like this:
public class TestClasssss implements ITest{
private String text;
}
And I trying to use this class inside my app unit tests project.
So, if I copy this classes inside my android's unit test project it compiles ok and all working as expected, however if this class and interface declared in app source folder, application do not compile and crash with
Error:(30, 10) error: cannot access ITest bad class file: ~\ITest.class
default method found in version 50.0 classfile
Please remove or make sure it appears in the correct subdirectory of the classpath.
So, how could I fix this strange behaviour?
My graddle config looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter()
}
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
apt {
arguments {
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
}
}
android {
compileSdkVersion 24
buildToolsVersion '24.0.1'
defaultConfig {
applicationId "io.projectname"
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
testOptions {
unitTests.returnDefaultValues = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res/controls',
'src/main/res/fragments',
'src/main/res/activities',
'src/main/res/views',
'src/main/res'
]
}
}
}
ext {
JUNIT_VERSION = '4.12'
DAGGER_VERSION = '2.2'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.111-beta'
testCompile "org.robolectric:robolectric:3.1.1"
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.roughike:bottom-bar:1.3.4'
compile 'com.aurelhubert:ahbottomnavigation:1.2.3'
compile 'joda-time:joda-time:2.9.4'
compile 'com.annimon:stream:1.0.9'
compile 'com.kyleduo.switchbutton:library:1.4.1'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
compile('eu.davidea:flexible-adapter:5.0.0-SNAPSHOT') {
changing = true
}
compile 'com.github.aakira:expandable-layout:1.5.1#aar'
compile "cn.aigestudio.wheelpicker:WheelPicker:1.1.2"
compile 'net.sf.biweekly:biweekly:0.5.0'
//Dagger dependencies started
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
testCompile "junit:junit:$JUNIT_VERSION"
testApt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
//Dagger dependencies finished
provided 'org.projectlombok:lombok:1.16.10'
}
Make sure that you set up source and target compatibility correctly
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
I was dealing with the same issue, it appears to be some kind of conflict between the compiled java source version accepted on android and the output produced by the code compiled with retrolambda.
The problem raises when you use the default notation for funcional interfaces method.
There's some kind of limited support for that in the retrolambda plugin, quoting the readme of the repo (orfjackal/retrolambda):
retrolambda.defaultMethods
Whether to backport default methods and static methods on interfaces.
LIMITATIONS: All backported interfaces and all classes which implement
them or call their static methods must be backported together,
with one execution of Retrolambda.
Disabled by default. Enable by setting to "true"
So you can try using this in your android module's build.gradle file:
...
android {
...
}
retrolambda {
defaultMethods = true
}
In my case this does not work, but my scenario was quite different than yours. I was having the retrolambda code on one library project and then trying to use that on another app project.
Also I could not get the Jack & Jill compiler to work (theres some kind of java8 support with Jack enabled, see Enable Java 8 Features and the Jack Toolchain at android reference), one cryptic "NullPointer" raises at ./gradlew assembleDebug, so I suggest to avoid jackOptions for now.
Good luck!
I think that you probably need to enable the Jack compiler. You need the following:
Android Studio > 2.1
Default methods are only available if you are targetting API Level 24
Your gradle needs to look something like this:
android {
...
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
This is the Java 8 Language Feature Page in the Android Documentation
I had this issue after using dex2jar. According to https://gitlab.ow2.org/asm/asm/blob/master/asm/src/main/java/org/objectweb/asm/Opcodes.java#L264, version 50 of the JVM bytecode represents Java 1.6, while my dex file was designed to run on version 52 (1.8). I used another dex2jar utility (which should work on any jar, not just dex) to change the version to 1.8. The source is at https://github.com/pxb1988/dex2jar/blob/2.x/dex-tools/src/main/java/com/googlecode/dex2jar/tools/ClassVersionSwitch.java, the command is d2j-class-version-switch.sh 8 <source jar> <destination jar>.
Are you sure that your gradle build is using jdk1.8+? It seems like the build is trying to utilize a class that was built using 1.8 but being tested during build using a lower version.
try:
gradle clean build
OR
gradlew clean build
If you are using Android Studio try to Clean Project, then Build project. If it doesn't help too, then Click to File -> "Invalidate Caches / Restart". It must help
About a week ago I asked this question
Why is library module android.support.test not visible in add dependency
After much head scratching and project setup morphing I discovered that this app/build.gradle dependency configuration gets me so much further than ever before in that at least the project compiles but does not build when attempting to run:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.my.package.name"
minSdkVersion 8
targetSdkVersion 22
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets { main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] } }
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:support-v4:22.1.0'
compile 'com.android.support.test.espresso:espresso-core:2.1'
compile 'com.android.support.test:testing-support-lib:0.1'
}
Notice compile instead of androidTestCompile on the testing support dependencies. Using androidTestCompile results in the problems noted in my previous question identified above.
Also notice the two srcDirs in the sourceSets declaration. That declaration was automatically set when I manually created the androidTest/java directory. Should this be declared differently?
Also too, getDefaultProguardFile is underlined in the ide with the tool tip "cannot resolve symbol 'getDefaultProguardFile'". In case that is crucial.
This new revelation, switching androidTestCompile to compile, leads me to believe there is something wrong with the way I set up the project structure for the unit test. Here is a picture of my project structure:
I should mention that this project/module structure was automatically created when migrating from Eclipse. By the icon decorations it looks like it at least recognizes my test class as a test class.
But now I am stuck at this error:
Error:Execution failed for task ':mymodule:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\myuser\AppData\Local\Android\sdk\build-tools\22.0.1\dx.bat --dex --no-optimize --output C:\Users\myuser\AndroidstudioProjects\myproject\mymodule\build\intermediates\dex\debug --input-list=C:\Users\myuser\AndroidstudioProjects\myproject\mymodule\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/test/BuildConfig;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Not sure if this is coming from my project setup or if it is coming from the libraries due to using compile on the support.test libraries.
Any advice on why androidTestCompile doesn't work is appreciated.
Also I just 2 days ago took all the latest updates from SDK Manager to 22.0.1 to no avail.
Another thing I noticed is the only jar I seem to find containing package com.google.common.* is in the espresso library. (com.google.common.* is a dependency of the testing libraries.) But when I inspect the espresso library jar with winzip all of the com.google.common.* package folder structure is there but there are no .class files in the package folders nor subfolders. Just mentioning that in case it lends a clue. Perhaps it is somewhere else also that I had missed.
Thanks!
Edit:
my source sets now look like this
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
}
and dependencies
dependencies {
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:support-v4:22.1.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}
I still get can't resolve android.support.test in my test class (test is colored red on these lines):
import android.support.test.InstrumentationRegistry;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
shouldn't I see a testing-support, espresso-core and espresso-contrib in my External libraries?
Below is my working Espresso gradle setup based on Android Studio 1.1.0 + Espresso 2.0 + Support Library v11 + gradle environment. It looks likely that you missed androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0' library.
dependencies {
// ...
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}
android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
packagingOptions {
//...
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['res']
}
}
}
About the directory, yes. just maintain androidTest and main under src folder. But, your setting does not make IDE to recognize androidTest folder as a test project folder. For that, two projects with same package name causes multi dex error I think. Use androidTestCompile to espresso-related lines in gradle dependencies and clean/rebuild project.
Note that you have to set all referenced projects gradle to same testInstrumentationRunner.
I also spent times to make it work. I wrote Korean tutorial to setup and run Espresso. Sorry about the language but screenshots might be helpful or you can try Google translate to read it.
EDIT. APPENDED BELOW
I thought why your IDE did not show green color in androidTest folder (means Test Project), and found your gradle setup seems to be wrong.
The line
{ main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] } } make IDE to recognize androidTest is a Project folder not Test Project folder. remove second one. androidTest will be automatically recognized as a Test Project.
I have project in eclipse and use android 2.3.3(API 10), but when I need import this project to android studio 0.4.6 thin android show me massage to fixed my project after I click fixed show me error `"Execution failed for task ':preBuild'.> Build Tools Revision 19.0.0+ is required."
please how I can fixed this error.
That my gredle-wrapper .properties:
#Thu Apr 17 01:07:57 PDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
That my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 8
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['use','src']
resources.srcDirs = ['use','src']
aidl.srcDirs = ['use','src']
renderscript.srcDirs = ['use','src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
Please till me, any version eclipse I can export project to import in android studio.
All version eclipse is true to export.
You need to update the Build Tools Revision to version 19.0.0
open your sdk manager and update ( use the sdk directory associated with android studio not eclipse)
You might as well try to migrate your project from eclipse to make it easier when importing it in eclipse.
Let me know if this is not working
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.