I am currently trying to install Otto into my project. Everything went as expected following the steps here http://square.github.io/otto/ but when I register my activities, I do not receive callbacks.
In my App class I have the singleton
private static Bus bus;
public static Bus getEventBus() {
if(bus == null) {
bus = new Bus(ThreadEnforcer.MAIN);
}
return bus;
}
Then in my BaseActivity class I have this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentView());
App.getEventBus().register(BaseActivity.this);
}
This is pseudo code but really these are the only methods I have in these classes. I also have suspicion of my gradle so my gradle file looks as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "wallfly.io.wallfly"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations {
all*.exclude group: 'org.apache.httpcomponents'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/jackson-all-1.9.9.jar')
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/httpclient-4.5.1.jar')
compile files('libs/httpcore-4.3.1.jar')
compile files('libs/httpmime-4.3.1.jar')
compile 'com.squareup:otto:1.3.8'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
I am using Otto at work and it goes really well. However I cannot get it to work at home. I am lost as it seems no one else has encountered this problem. Any help or resources would be greatly appreciated.
Related
While Trying to implement Admobs in project I m facing the below issue during build apk process.
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/iid/zzc.class
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
defaultConfig {
// ...
multiDexEnabled true
}
dexOptions {
jumboMode true
}
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "eazy.picsart"
minSdkVersion 16
targetSdkVersion 23
versionCode 2
versionName "2.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [appPackageName: "${applicationId}"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
/* compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}*/
/* 3) Exclude duplicate licenses */
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
pickFirst 'AndroidManifest.xml'
exclude 'com/google/android/gms/ads/AdActivity.class'
}
aaptOptions{
cruncherEnabled = false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
compile 'com.adobe.creativesdk.foundation:auth:0.9.1251'
compile 'com.adobe.creativesdk:image:4.8.4'
compile 'com.localytics.android:library:3.8.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-ads:11.0.1'
}
I have got an awkward problem on my Android App. When i build my app on Android Studio, build ends with 704 errors but app works on my test device correctly. I can't figured out the problem. I searched on Google and found some answers in stackoverflow but they did not help me. Because i don't use proguard right know on my project and the answers are all about proguard.
And below codes are my app level gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
repositories {
maven {
url "http://dl.bintray.com/piasy/maven"
}
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "***.***.***"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'Boolean', 'crashlyticsEnabled', 'true'
buildConfigField 'Boolean', 'logEnabled', 'true'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'Boolean', 'crashlyticsEnabled', 'true'
buildConfigField 'Boolean', 'logEnabled', 'false'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/rxjava.properties'
}
dexOptions {
javaMaxHeapSize "4g" //specify the heap size for the dex process
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile "com.android.support:recyclerview-v7:23.1.1"
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile project(':chatlibrary')
compile 'com.amazonaws:aws-android-sdk-sns:2.2.14'
compile 'com.norbsoft.typefacehelper:library:0.9.0'
compile 'com.github.piasy:rxscreenshotdetector:1.1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.7#aar') {
transitive = true;
}
compile('com.digits.sdk.android:digits:2.0.6#aar') {
transitive = true;
}
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'com.github.GDG-Korea:PinterestLikeAdapterView:29697e2c24'
}
Thanks for your helps...
Hy! I am having following problem in my Android project
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/net/compatibility/WebAddress.class
I Know this is because of conflict in dependencies. I looked into dependencies but not able to configure which dependencies causing this issue. I am pasting my gradle code bellow
Module 1 :
android {
//useLibrary 'org.apache.http.legacy'
compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK)
targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
}`sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['res']
}
test {
java.srcDirs = ['src/test/java']
}
}`compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7` }
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}`lintOptions {
abortOnError false
}
checkstyle {
ignoreFailures = true
}
buildToolsVersion '25.0.3'`}`dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':webViewMarker')
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'com.squareup:otto:1.3.8'`}`
Module 2
apply plugin: 'com.android.library'`ext {
bintrayRepo = 'maven'
bintrayName = 'folioreader'
publishedGroupId = 'com.folioreader'
libraryName = 'WebViewMarker'
artifact = 'webViewMarker'
libraryDescription = 'An epub reader for Android'
siteUrl = 'https://github.com/FolioReader/FolioReader-Android'
gitUrl = 'https://github.com/FolioReader/FolioReader-Android.git'
libraryVersion = '0.2.5'
developerId = 'mobisystech'
developerName = 'Folio Reader'
developerEmail = 'mahavir#codetoart.com'
licenseName = 'FreeBSD License'
licenseUrl = 'https://en.wikipedia.org/wiki/FreeBSD_Documentation_License#License'
allLicenses = ["FreeBSD"]`}`android {
compileSdkVersion 19
buildToolsVersion '25.0.3'
defaultConfig {
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK)
targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}`
}
apply from: '../folioreader/bintray/installv1.gradle'
apply from: '../folioreader/bintray/bintrayv1.gradle'
Main Module
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}`}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.ebook.stev_ebook"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':folioreader')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.8.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'org.apache.httpcomponents:httpmime:4.5.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.stripe:stripe-android:+'
compile('com.twitter.sdk.android:twitter:1.3.2#aar') {
transitive = true;
}
compile 'com.android.support:multidex:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.google.android.gms:play-services-plus:9.0.0'
compile 'com.google.android.gms:play-services-auth:9.0.0'
}
Please comment this
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
Try Rebuilding again. Since it's a third party library , there is a chance that it might be causing the trouble
It means you are using different version of support and all android libraries for example you are using support library version 25.0.1 in one module and version 22.2.1 in another and of course you should add just one of these library to your dependencies when you add one library in one module you should not add it to build.gradle file of second.
Solution : remove duplicate libraries.
I have generated my signed apk for product flavors, but when i try to install the apk in my device, it says "App not installed"
Here is my gradle file code :-
android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.app.olivesync"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors{
main {
applicationId "com.app.olivesync"
}
resonance {
applicationId "com.app.resonance"
}
}
dependencies {
compile('com.fasterxml.jackson.core:jackson-annotations:2.2.2') {
exclude group: 'com.fasterxml.jackson.core'
}
compile('com.fasterxml.jackson.core:jackson-databind:2.2.3') {
exclude group: 'com.fasterxml.jackson.core'
}
compile('com.fasterxml.jackson.core:jackson-core:2.2.3') {
exclude group: 'com.fasterxml.jackson.core'
}
compile 'com.android.support:support-v4:25.3.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.roomorama:caldroid:3.0.1'
compile 'com.android.support:design:25.3.0'
compile 'com.google.android.gms:play-services-gcm:10.2.0'
compile 'com.microsoft.azure:notification-hubs-android-sdk:0.4#aar'
compile 'com.microsoft.azure:azure-notifications-handler:1.0.1#aar'
compile 'com.google.firebase:firebase-crash:10.2.0'
compile 'com.github.shell-software:fab:1.1.2'
compile 'com.android.support:cardview-v7:25.3.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.github.iammert:MaterialIntroView:1.6.0'}
repositories {
maven { url "https://jitpack.io" }
}
apply plugin: 'com.google.gms.google-services'
change your version and then try to build sign apk. Hope it will work.
I'm having trouble running tests in Android Studio. I've read through a load of posts with the same problem here on Stack Overflow, but to no avail. Just to be clear, I want to test in the emulator and not in the JVM.
Run configuration:
Output:
Running tests
Test running startedTest running failed: No test results
Empty test suite.
Build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "ntnu.stud.markul.crowdshelf"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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.0.1'
// Unit testing dependencies
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.3') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
The test class (located in /src/androidTest/java/com/appname/app/):
#RunWith(AndroidJUnit4.class)
public class NetworkAndDBInstrumentationTest extends ActivityInstrumentationTestCase2<MainActivity> {
private MainActivity mActivity;
public NetworkAndDBInstrumentationTest() {
super(MainActivity.class);
}
#Before
public void setUp() throws Exception {
super.setUp();
// Injecting the Instrumentation instance is required
// for your test to run with AndroidJUnitRunner.
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
#Test
public void typeOperandsAndPerformAddOperation() {
NetworkController.getCrowd("55f01f29f0a5fad2120bb1db");
System.out.print("ok");
Log.d("1TEST", "1TEST");
}
#After
public void tearDown() throws Exception {
super.tearDown();
}
}
I got it to work using this:
#RunWith(AndroidJUnit4.class)
#LargeTest
public class NetworkAndDBInstrumentationTest {
//use the following annotation and declare an ActivityTestRule for your activity under test
#Rule
public ActivityTestRule<RealmActivity> mActivityRule = new ActivityTestRule(RealmActivity.class);
//use #Before to setup your test fixture
#Before
public void setUp() { }
//annotate all test methods with
#Test
public void testGetCrowd() {
Assert.assertEquals(1, 1);
}
#After
public void tearDown() { }
}
Where RealmActivity is the Activity I want to test. Build.gradle and everything else is as in the question post. Now, a follow-up question: What does it matter that I make the #Rule with RealmActivity? Can't I use other Activities in that test? Can I make a Activity-independent test?
Your configuration looks right. You can try to add this to your build.gradle file:
/*
* Working build.gradle test config. Gradle version 1.3.0
*/
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "test.your.app"
minSdkVersion 15
targetSdkVersion 23
versionCode versionMajor * 100 + versionMinor * 10 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
}
configurations.all {
// Currently espresso is dependent on support-annotations:22.2.1
resolutionStrategy.force 'com.android.support:support-annotations:22.2.1'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
disable 'SetJavaScriptEnabled'
disable 'InvalidPackage'
abortOnError false
textReport true
textOutput 'stdout'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
applicationIdSuffix '.debug'
testCoverageEnabled = true
}
release {
}
}
productFlavors {
dev {
versionName "DEV"
}
}
sourceSets { //this one may not be needed. But wont hurt.
androidTest.setRoot('src/androidTest')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Android
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:support-v13:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-annotations:23.0.1'
// Google Play Services
compile 'com.google.android.gms:play-services-base:7.8.0'
compile 'com.google.android.gms:play-services-analytics:7.8.0'
compile 'com.google.android.gms:play-services-appindexing:7.8.0'
// Integration Tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude group:'com.android.support', module:'support-v4'
exclude module: 'recyclerview-v7'
}
// Unit Tests
testCompile 'junit:junit:4.12'
testCompile 'com.google.truth:truth:0.25'
//Mocking
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile "com.google.dexmaker:dexmaker:${DEXMAKER_VERSION}"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:${DEXMAKER_VERSION}"
androidTestApt "com.google.dagger:dagger-compiler:${DAGGER_VERSION}"
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test:runner:0.3'
// Leak detection
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
}
You could also try using JUnit 3 style to see if that gets better results. Are you extending ApplicationTestCase? Try and get things working there.
I think you need add this line in your dependencies:
androidTestCompile ('org.hamcrest:hamcrest-library:1.3')