1

I'm new to android so might be missing something obvious.

I'm running af small service simulating some calls, but having trouble with the service occasionally restarting mid task. It's not always the same task, and sometimes it doesn't happen at all.

the errors produced when the service restarts:

10-13 13:49:14.469 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Lcom/android/tools/fd/runtime/Server$SocketServerThread;
10-13 13:49:14.481 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/SimulatorService;
10-13 13:49:14.483 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/TestCase;
10-13 13:49:14.484 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Lcom/android/tools/fd/runtime/IncrementalChange;
10-13 13:49:14.486 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Lcom/android/tools/fd/runtime/InstantReloadException;
10-13 13:49:14.488 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/CaseInfo;
10-13 13:49:14.489 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/SimulatorService$1;
10-13 13:49:14.489 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/SimulatorService$2;
10-13 13:49:14.491 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/TransferHelper;
10-13 13:49:14.498 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Lorg/apache/commons/io/IOUtils;
10-13 13:49:14.503 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/SimulatorService$5;
10-13 13:49:14.504 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/SimulatorService$6;
10-13 13:49:14.505 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/SimulatorService$4;
10-13 13:49:14.507 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Ltest/callsimulator/SimulatorService$3;
10-13 13:49:14.510 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Landroid/support/v4/app/ActivityCompat;
10-13 13:49:14.513 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Landroid/support/v4/content/ContextCompat;
10-13 13:49:14.533 20691-20691/test.callsimulator D/CallSimulator: Sim number; 89450100140117176259
10-13 13:49:14.542 20691-20691/test.callsimulator V/HwPolicyFactory: : success to get AllImpl object and return....
10-13 13:49:14.544 20691-20691/test.callsimulator V/HwWidgetFactory: : successes to get AllImpl object and return....
10-13 13:49:14.627 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Lorg/apache/commons/io/output/StringBuilderWriter;
10-13 13:49:14.632 20691-20691/test.callsimulator E/art: ClassLinker::FindClass not found:Lorg/apache/commons/io/Charsets;

if I open the app, i get a lot more of these errors of the above kind, but they dont have any immediate effect on the app. The activity in the app does nothing more than start the service if it hasn't already been started.

I've found similar questions where the answers all seem to point towards the gradle property files, adding support libraries downloading missing packages, but their solutions hasn't worked for me.

build.gradle in app folder:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"

defaultConfig {
    applicationId "test.callsimulator"
    minSdkVersion 22
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:support-v13:24.2.1'
}

build.gradle in project folder:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

What am i missing ?

KristianMedK
  • 1,659
  • 6
  • 24
  • 52

7 Answers7

2

It's hard to say but it seems an issue related to the version of gradle you are using or to Instant Run. What I suggest is:

  1. Update Android Studio to the last version (2.2.2)
  2. Update the Android gradle plugin replacing classpath 'com.android.tools.build:gradle:2.1.2' with classpath 'com.android.tools.build:gradle:2.2.2'
  3. Update the gradle wrapper version to the one suggested by Google (open your_project/gradle/wrapper/gradle-wrapper.properties and set the last line to distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip)

Steps 2 and 3 should be performed by Android Studio as soon as you update it.

Clean and rebuild your project.

If this doesn't fix your issue, try disabling Instant Run (AndroidStudio -> Preferences -> Build, Execution, Deployment -> Instant Run -> Uncheck the 'enable instant run to hot swap code/resource changes on deploy').

Clean and rebuild your project again.

And finally, it could be an issue connected to the number of libraries/methods you are using (are you using some jars file inside the libs folder?). Follow this guide to enable multidex.

Of course: clean and rebuild :)

Mimmo Grottoli
  • 5,758
  • 2
  • 17
  • 27
  • disabling instant run seems to have done the trick. 2+ days spend trying to figure this out, and all i had to do was click a checkbox. – KristianMedK Oct 24 '16 at 05:52
1

1.Go to Project Structure -> Dependencies

2.Click '+' in the upper right corner and select "Library dependency"

3.In the search field type which library you want to add.ex You want to add "org.apache.directory.studio:org.apache.commons.io".
4.select and add this library.

OR

5.Clear App Cache.

6.Invalidate caches/Restart Android studio.

(Happy Coding :))

MIkka Marmik
  • 1,101
  • 11
  • 29
1

You are getting ClassNotFoundException .

ClassNotFoundException Comes when Java Virtual Machine tries to load a particular class and doesn't found the requested class in classpath.

Quick Solutions

Check your classpath contains that jar or compile library, if your classpath doesn't contain the jar or compile library then just add that class in your classpath.

Its most common problem for new comer . You can check this answer .

  1. Android Studio: Add jar

Then Clean-Rebuild & Run your Project .

FYI

Don't call same library from Gradle section . If you Add same jar in your gradle sections then Duplicate zip entry compile time error arising .

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

I believe the problem is with gradle configuration of the line

compile 'org.apache.directory.studio:org.apache.commons.io:2.4'

May the problem would be jar file which you trying to compile may not present in your sdk library.

I can say the solution will be download the Apache jars whatever you need from the Maven repository and add it in to your project as a library(The given Url having that part too).

The below link will be very helpful to you to solve the problem

Add Apache common collections

Community
  • 1
  • 1
Bethan
  • 971
  • 8
  • 23
  • This is not the problem. [commons.io](http://www.methodscount.com/?lib=org.apache.directory.studio%3Aorg.apache.commons.io%3A2.4) is in `jcenter`. Adding the library to `libs` folder is a very bad solution, which may lead to dependency hell. – R. Zagórski Oct 18 '16 at 08:01
  • when i check External libraries commons.io is present, and the .jar file exists at the location – KristianMedK Oct 18 '16 at 11:29
0

Problem here compile 'org.apache.directory.studio:org.apache.commons.io:2.4' You need to download the jar files and put it in your lib folder. Then include it in your gradle dependencies

Download Apache Commons io

ZeroOne
  • 8,996
  • 4
  • 27
  • 45
0

Try removing the proguard configuration

Verift that Actiivty & service files are ignored.

or keep the Activty & required class by adding
-keep class .**

Rajesh Gopu
  • 863
  • 9
  • 33
0

Just an Idea but do you have all the necessary imports? All the support libraries?

Ishan Manchanda
  • 459
  • 4
  • 19