0

i am using commonsware sample application for auto update of my application which will be placed on server. but it is throwing me the exception of ClassNotFound

Logcat

10-29 12:08:45.164: E/CWAC-Update(361): Exception in applying update
10-29 12:08:45.164: E/CWAC-Update(361): java.io.FileNotFoundException: /.CWAC-Update/update.apk (No such file or directory)
10-29 12:08:45.164: E/CWAC-Update(361):     at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
10-29 12:08:45.164: E/CWAC-Update(361):     at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
10-29 12:08:45.164: E/CWAC-Update(361):     at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
10-29 12:08:45.164: E/CWAC-Update(361):     at java.io.FileOutputStream.<init>(FileOutputStream.java:69)
10-29 12:08:45.164: E/CWAC-Update(361):     at com.commonsware.cwac.updater.SimpleHttpDownloadStrategy.openDownloadFile(SimpleHttpDownloadStrategy.java:92)
10-29 12:08:45.164: E/CWAC-Update(361):     at com.commonsware.cwac.updater.SimpleHttpDownloadStrategy.downloadAPK(SimpleHttpDownloadStrategy.java:48)
10-29 12:08:45.164: E/CWAC-Update(361):     at com.commonsware.cwac.updater.UpdateService.downloadAndInstall(UpdateService.java:70)
10-29 12:08:45.164: E/CWAC-Update(361):     at com.commonsware.cwac.updater.UpdateService.doWakefulWork(UpdateService.java:36)
10-29 12:08:45.164: E/CWAC-Update(361):     at com.commonsware.cwac.wakeful.WakefulIntentService.onHandleIntent(WakefulIntentService.java:103)
10-29 12:08:45.164: E/CWAC-Update(361):     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
10-29 12:08:45.164: E/CWAC-Update(361):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 12:08:45.164: E/CWAC-Update(361):     at android.os.Looper.loop(Looper.java:123)
10-29 12:08:45.164: E/CWAC-Update(361):     at android.os.HandlerThread.run(HandlerThread.java:60)
10-29 12:17:39.586: E/CWAC-Update(436):     at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)

Here is the code

/***
Copyright (c) 2012 CommonsWare, LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package com.example.medecure;

import android.app.Activity;
import android.app.Notification;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.commonsware.cwac.updater.ConfirmationStrategy;
import com.commonsware.cwac.updater.DownloadStrategy;
import com.commonsware.cwac.updater.InternalHttpDownloadStrategy;
import com.commonsware.cwac.updater.NotificationConfirmationStrategy;
import com.commonsware.cwac.updater.SimpleHttpDownloadStrategy;
import com.commonsware.cwac.updater.SimpleHttpVersionCheckStrategy;
import com.commonsware.cwac.updater.UpdateRequest;
import com.commonsware.cwac.updater.VersionCheckStrategy;

public class UpdaterDemoActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView versionCodeLabel=(TextView)findViewById(R.id.versionCode);

    try {
      int currentVersionCode=
          getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;

      versionCodeLabel.setText(String.valueOf(currentVersionCode));
    }
    catch (Exception e) {
      Log.e("UpdaterDemoActivity", "An impossible exception", e);
    }

    UpdateRequest.Builder builder=new UpdateRequest.Builder(this);
    builder.setVersionCheckStrategy(buildVersionCheckStrategy())
           .setPreDownloadConfirmationStrategy(buildPreDownloadConfirmationStrategy())
           .setDownloadStrategy(buildDownloadStrategy())
           .setPreInstallConfirmationStrategy(buildPreInstallConfirmationStrategy())
           .execute();
  }

  VersionCheckStrategy buildVersionCheckStrategy() {
    return(new SimpleHttpVersionCheckStrategy(
               "http://www.medecure.com/v2/android/update.json"));
                                           //   "http://misc.commonsware.com/update.json"));
  }

  @SuppressWarnings("deprecation")
ConfirmationStrategy buildPreDownloadConfirmationStrategy() {
    // return(new ImmediateConfirmationStrategy());
    Notification n=
        new Notification(android.R.drawable.stat_notify_chat,
                         "Update availalble", System.currentTimeMillis());

    n.setLatestEventInfo(this, "Update Available",
                         "Click to download the update!", null);
    n.flags|=Notification.FLAG_AUTO_CANCEL;

    return(new NotificationConfirmationStrategy(n));
  }

  DownloadStrategy buildDownloadStrategy() {
    if (Build.VERSION.SDK_INT>=11) {
      return(new InternalHttpDownloadStrategy());
    }

    return(new SimpleHttpDownloadStrategy());
  }

  @SuppressWarnings("deprecation")
ConfirmationStrategy buildPreInstallConfirmationStrategy() {
//    return(new ImmediateConfirmationStrategy());
    Notification n=
        new Notification(android.R.drawable.stat_notify_chat,
                         "Update ready to install", System.currentTimeMillis());

    n.setLatestEventInfo(this, "Update Ready to Install",
                         "Click to install the update!", null);
    n.flags|=Notification.FLAG_AUTO_CANCEL;

    return(new NotificationConfirmationStrategy(n));
  }
}
4

2 回答 2

1

There's two accepted ways to include jar libraries for Android:

  1. Place the library in the libs/ folder at the root of your project.
  2. Include the library in your build path. If you choose this route, you will also need to export the library (Under Order and Exports in Eclipse).
于 2012-10-29T06:44:23.557 回答
0

Check your build path. The libraries may not be in your build path. The error clearly says that it's not able to find the class.

om.commonsware.cwac.updater.UpdateRequest
于 2012-10-29T06:34:43.970 回答