My App has the following Parameters:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "de.munich.myApp"
minSdkVersion 17
targetSdkVersion 23
multiDexEnabled true
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
I included support package v7:
dependencies {
compile 'com.google.code.gson:gson:2.4'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
}
And now i try to start my App on a Galaxy Ace with Android Version 4.4.2 (API Level 19) and i get many errors because some methods referenced by the android.support.v7 could not be found:
Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
Ofcourse the app crashes.
Is there any way for me to fix those problems without having to increase the minSdkVersion?
EDIT
import android.app.Notification;
import android.content.Context;
import android.support.v4.app.NotificationCompat;
public class HelperNotification {
/**
*
* #param context
* #param title
* #param message
* #return
*/
public static NotificationCompat.Builder buildNotification(Context context, String title, String message) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(title);
builder.setContentText(message);
int defaults = 0;
defaults = defaults | Notification.DEFAULT_LIGHTS;
defaults = defaults | Notification.DEFAULT_VIBRATE;
defaults = defaults | Notification.DEFAULT_SOUND;
builder.setDefaults(defaults);
return builder;
}
}
EDIT 2
I/dalvikvm: Could not find method android.os.UserManager.getApplicationRestrictions, referenced from method com.google.android.gms.common.zze.zzaq
W/dalvikvm: VFY: unable to resolve virtual method 1747: Landroid/os/UserManager;.getApplicationRestrictions (Ljava/lang/String;)Landroid/os/Bundle;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0012
E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
W/dalvikvm: VFY: unable to resolve check-cast 35 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/zze;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x000e
I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.zze.zzi
W/dalvikvm: VFY: unable to resolve virtual method 605: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b
I/GMPM: App measurement is starting up, version: 8487
I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
E/GMPM: Scheduler not set. Not logging error/warn.
E/GMPM: Uploading is not possible. App measurement disabled
D/dalvikvm: GC_CONCURRENT freed 265K, 16% free 8722K/10356K, paused 5ms+2ms, total 26ms
W/dalvikvm: VFY: unable to find class referenced in signature (Lde/hof/my_project/enums/status/images/StatusImageScale;)
W/dalvikvm: VFY: unable to resolve static field 34720 ($SwitchMap$de$hof$my_project$enums$status$images$StatusImageScale) in Lde/hof/my_project/fragments/FragmentSplash$1;
D/dalvikvm: VFY: replacing opcode 0x62 at 0x0000
E/dalvikvm: Could not find class 'de.hof.my_project.tasks.images.TaskImagesScale', referenced from method de.hof.my_project.fragments.FragmentSplash.onViewCreated
W/dalvikvm: VFY: unable to resolve new-instance 9154 (Lde/hof/my_project/tasks/images/TaskImagesScale;) in Lde/hof/my_project/fragments/FragmentSplash;
D/dalvikvm: VFY: replacing opcode 0x22 at 0x0003
D/dalvikvm: DexOpt: unable to opt direct call 0xf89d at 0x05 in Lde/hof/my_project/fragments/FragmentSplash;.onViewCreated
I added some mor log outputs. This is when i run my app on a Samsung Galaxy S3 with API 17 (my minimum required API). Last week, before i updated my libraries from 23.0 to 23.2 everything was working. Now it seems like he cant find some of the classes i defined.
Well to answer the question on the title of your question you should change Notification to NotificationCompat, i.e.:
NotificationCompat.Builder.
The regular Notification.Builder has setLocal available only since API 20.
I found the solution.
The problem was related to the 65K Methods Count.
I did what android recommended in the link and so i
was able to install the app again on devices with older
API's.
Related
I added new project in my Firebase account like all the time and downloaded google-services.json setting file and successfully install it and the app works however not with firebase service the following is my debug , while the app crash.
please note that this error shows up when i try to add : implementation 'com.google.firebase:firebase-core:16.0.4' and in android studio it shows no error in gradle
10/08 19:55:40: Launching app
$ adb push C:\xxx\app\build\outputs\apk\debug\app-debug.apk /data/local/tmp/com.xxx.insidecartoon
$ adb shell pm install -t -r "/data/local/tmp/com.xxx.xxx"
pkg: /data/local/tmp/com.xxx.xxx
Success
APK installed in 27 s 241 ms
$ adb shell am start -n "com.xxx.xxx/com.xxx.xxx.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.xxx.xxx.test | com.xxx.xxx
Connecting to com.xxx.xxx
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/System.out: Sending WAIT chunk
W/ActivityThread: Application com.xxx.xxx is waiting for the debugger on port 8100...
I/dalvikvm: Debugger is active
I/System.out: Debugger has connected
waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8602', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1405)
I/dalvikvm: Could not find method android.content.Context.createDeviceProtectedStorageContext, referenced from method android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext
W/dalvikvm: VFY: unable to resolve virtual method 565: Landroid/content/Context;.createDeviceProtectedStorageContext ()Landroid/content/Context;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.getCodeCacheDir, referenced from method android.support.v4.content.ContextCompat.getCodeCacheDir
W/dalvikvm: VFY: unable to resolve virtual method 573: Landroid/content/Context;.getCodeCacheDir ()Ljava/io/File;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.getColor, referenced from method android.support.v4.content.ContextCompat.getColor
W/dalvikvm: VFY: unable to resolve virtual method 574: Landroid/content/Context;.getColor (I)I
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v4.content.ContextCompat.getColorStateList
W/dalvikvm: VFY: unable to resolve virtual method 575: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.getDataDir, referenced from method android.support.v4.content.ContextCompat.getDataDir
W/dalvikvm: VFY: unable to resolve virtual method 577: Landroid/content/Context;.getDataDir ()Ljava/io/File;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.getDrawable, referenced from method android.support.v4.content.ContextCompat.getDrawable
W/dalvikvm: VFY: unable to resolve virtual method 580: Landroid/content/Context;.getDrawable (I)Landroid/graphics/drawable/Drawable;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.getNoBackupFilesDir, referenced from method android.support.v4.content.ContextCompat.getNoBackupFilesDir
W/dalvikvm: VFY: unable to resolve virtual method 587: Landroid/content/Context;.getNoBackupFilesDir ()Ljava/io/File;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.isDeviceProtectedStorage, referenced from method android.support.v4.content.ContextCompat.isDeviceProtectedStorage
W/dalvikvm: VFY: unable to resolve virtual method 600: Landroid/content/Context;.isDeviceProtectedStorage ()Z
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.startForegroundService, referenced from method android.support.v4.content.ContextCompat.startForegroundService
W/dalvikvm: VFY: unable to resolve virtual method 615: Landroid/content/Context;.startForegroundService (Landroid/content/Intent;)Landroid/content/ComponentName;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.Context.isDeviceProtectedStorage, referenced from method com.google.android.gms.internal.measurement.zzsl.init
W/dalvikvm: VFY: unable to resolve virtual method 600: Landroid/content/Context;.isDeviceProtectedStorage ()Z
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0009
V/FA: Registered activity lifecycle callback
D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
I/FirebaseInitProvider: FirebaseApp initialization successful
V/FA: onActivityCreated
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zze; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zze;' failed
VFY: unable to find class referenced in signature (Lcom/google/android/gms/ads/internal/client/zze;)
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zze; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zze;' failed
I/dalvikvm: Could not find method com.google.android.gms.ads.internal.client.zze.zzb, referenced from method com.google.android.gms.ads.internal.client.zzac.zzH
W/dalvikvm: VFY: unable to resolve virtual method 17122: Lcom/google/android/gms/ads/internal/client/zze;.zzb (Landroid/content/Context;Lcom/google/android/gms/ads/internal/client/AdSizeParcel;Ljava/lang/String;Lcom/google/android/gms/internal/zzew;)Lcom/google/android/gms/ads/internal/client/zzu;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x001f
I/dalvikvm: Could not find method com.google.android.gms.common.internal.zzx.zzb, referenced from method com.google.android.gms.ads.AdRequest$Builder.setContentUrl
W/dalvikvm: VFY: unable to resolve static method 21535: Lcom/google/android/gms/common/internal/zzx;.zzb (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
D/dalvikvm: VFY: replacing opcode 0x71 at 0x0002
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zze; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zze;' failed
E/dalvikvm: Could not find class 'com.google.android.gms.ads.internal.client.zze', referenced from method com.google.android.gms.ads.internal.client.zzn.<init>
W/dalvikvm: VFY: unable to resolve new-instance 2192 (Lcom/google/android/gms/ads/internal/client/zze;) in Lcom/google/android/gms/ads/internal/client/zzn;
D/dalvikvm: VFY: replacing opcode 0x22 at 0x000a
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zze; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zze;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zze; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zze;' failed
VFY: unable to find class referenced in signature (Lcom/google/android/gms/ads/internal/client/zze;)
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zzaf; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zzaf;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zzaf; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zzaf;' failed
VFY: unable to find class referenced in signature (Lcom/google/android/gms/ads/internal/client/zzaf;)
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/internal/zzcv; (3038)
Link of class 'Lcom/google/android/gms/internal/zzcv;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/internal/zzcv; (3038)
Link of class 'Lcom/google/android/gms/internal/zzcv;' failed
W/dalvikvm: VFY: unable to find class referenced in signature (Lcom/google/android/gms/internal/zzcv;)
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/reward/client/zzf; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/reward/client/zzf;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/reward/client/zzf; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/reward/client/zzf;' failed
W/dalvikvm: VFY: unable to find class referenced in signature (Lcom/google/android/gms/ads/internal/reward/client/zzf;)
Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zze; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zze;' failed
D/dalvikvm: DexOpt: unable to opt direct call 0x42de at 0x0c in Lcom/google/android/gms/ads/internal/client/zzn;.<init>
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/client/zzaf; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/client/zzaf;' failed
D/dalvikvm: DexOpt: unable to opt direct call 0x427b at 0x1a in Lcom/google/android/gms/ads/internal/client/zzn;.<init>
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/internal/zzcv; (3038)
Link of class 'Lcom/google/android/gms/internal/zzcv;' failed
D/dalvikvm: DexOpt: unable to opt direct call 0x623a at 0x21 in Lcom/google/android/gms/ads/internal/client/zzn;.<init>
W/dalvikvm: Unable to resolve superclass of Lcom/google/android/gms/ads/internal/reward/client/zzf; (3038)
Link of class 'Lcom/google/android/gms/ads/internal/reward/client/zzf;' failed
D/dalvikvm: DexOpt: unable to opt direct call 0x46fd at 0x28 in Lcom/google/android/gms/ads/internal/client/zzn;.<init>
W/dalvikvm: DexOpt: resolve class illegal access: Lcom/google/android/gms/ads/internal/util/client/zza; -> Lcom/google/android/gms/common/zze;
I/dalvikvm: Could not find method com.google.android.gms.common.zze.isGooglePlayServicesAvailable, referenced from method com.google.android.gms.ads.internal.util.client.zza.zzU
W/dalvikvm: VFY: unable to resolve static method 22073: Lcom/google/android/gms/common/zze;.isGooglePlayServicesAvailable (Landroid/content/Context;)I
D/dalvikvm: VFY: replacing opcode 0x71 at 0x0000
I/dalvikvm: Could not find method com.google.android.gms.internal.zzne.zzsi, referenced from method com.google.android.gms.ads.internal.util.client.zza.zzW
W/dalvikvm: VFY: unable to resolve static method 27575: Lcom/google/android/gms/internal/zzne;.zzsi ()Z
D/dalvikvm: VFY: replacing opcode 0x71 at 0x0014
W/dalvikvm: Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/android/gms/ads/internal/client/zzn;
Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/android/gms/ads/internal/client/zzaa;
Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/android/gms/ads/AdRequest;
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x417e1da0)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xxx, PID: 29691
java.lang.NoClassDefFoundError: com.google.android.gms.ads.internal.client.zze
at com.google.android.gms.ads.internal.client.zzn.<init>(Unknown Source)
at com.google.android.gms.ads.internal.client.zzn.<clinit>(Unknown Source)
at com.google.android.gms.ads.internal.client.zzaa.<clinit>(Unknown Source)
at com.google.android.gms.ads.AdRequest.<clinit>(Unknown Source)
at com.google.android.gms.ads.AdRequest$Builder.<init>(Unknown Source)
at com.xxx.xxx.MainActivity.requestNewInterstitial(MainActivity.java:77)
at com.xxx.xxx.MainActivity.onCreate(MainActivity.java:49)
at android.app.Activity.performCreate(Activity.java:5541)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Disconnected from the target VM, address: 'localhost:8602', transport: 'socket'
my gradle info also i run android version 3.2 and gradle wrapper gradle-4.6
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "KING-DEV"
}
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
implementation 'com.google.firebase:firebase-core:16.0.4'
}
apply plugin: 'com.google.gms.google-services'**
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.1.0' // google-services plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Try applying plugin of google play services
apply plugin: 'com.google.gms.google-services'
To solve this, please change the following line of code:
compile 'com.google.android.gms:play-services-ads:8.4.0'
to
implementation 'com.google.android.gms:play-services-ads:16.0.0'
And remove ** after this line of code:
apply plugin: 'com.google.gms.google-services'
I get following exception log if I try to open my app on API 16 (on API 27 it is working):
V/FA: onActivityCreated
I/dalvikvm: Could not find method android.app.AlarmManager.setExactAndAllowWhileIdle, referenced from method com.text.app.utilities.COLNotification.addPreAlarm
VFY: unable to resolve virtual method 130: Landroid/app/AlarmManager;.setExactAndAllowWhileIdle (IJLandroid/app/PendingIntent;)V
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0021
I/dalvikvm: Could not find method android.app.AlarmManager.setExact, referenced from method com.text.app.utilities.COLNotification.addPreAlarm
W/dalvikvm: VFY: unable to resolve virtual method 129: Landroid/app/AlarmManager;.setExact (IJLandroid/app/PendingIntent;)V
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0084
W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/NotificationChannel;)
I/dalvikvm: Could not find method android.app.NotificationChannel.getSound, referenced from method com.text.app.utilities.COLNotification.buildNotification
W/dalvikvm: VFY: unable to resolve virtual method 264: Landroid/app/NotificationChannel;.getSound ()Landroid/net/Uri;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0131
W/dalvikvm: VFY: unable to resolve exception class 435 (Landroid/os/FileUriExposedException;)
W/dalvikvm: VFY: unable to find exception handler at addr 0x25e
W/dalvikvm: VFY: rejected Lcom/text/app/utilities/COLNotification;.buildNotification (Lcom/text/app/models/appModel;)V
W/dalvikvm: VFY: rejecting opcode 0x0d at 0x025e
W/dalvikvm: VFY: rejected Lcom/text/app/utilities/COLNotification;.buildNotification (Lcom/text/app/models/appModel;)V
W/dalvikvm: Verifier rejected class Lcom/text/app/utilities/COLNotification;
All warnings are correct because the methods like "NotificationChannel" are not existing in API 16.
And the code I use for example the "NotificationChannel" is not executed because I check for the Build.VERSION.SDK.INT!
What exactly is the problem? Can anybody help?
I used the "FileUriException" in a catch statement and this caused the the problem.
Instead of:
catch(FileUriException e) {
}
I do now:
catch(Exception e) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && e instanceof FileUriExposedException) {
}
}
I created an app that connects to ssh with my raspberry Pi and executes a python file. The command and the python file work like a charm when I connect from my windows pc but the app does nothing for some reason.
Here is the code:
import android.content.pm.PackageInstaller;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Properties;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.ByteArrayOutputStream;
import java.util.Properties;
public class MainActivity extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new AsyncTask<Integer, Void, Void>() {
#Override
protected Void doInBackground(Integer... params) {
try {
executeRemoteCommand("pi", "123456", "192.168.1.6", 22);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute(1);
}
public static String executeRemoteCommand(String username, String password, String hostname, int port)
throws Exception {
JSch jsch = new JSch();
Session session = jsch.getSession(username, hostname, port);
session.setPassword(password);
// Avoid asking for key confirmation
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
session.setConfig(prop);
session.connect();
// SSH Channel
ChannelExec channelssh = (ChannelExec)
session.openChannel("exec");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
channelssh.setOutputStream(baos);
// Execute command
channelssh.setCommand("cd /home/pi/Desktop | nohup python red.py");
//System.out.print("cd /home/pi/Desktop | nohup python red.py");
channelssh.connect();
channelssh.disconnect();
return baos.toString();
}
}
This is the Android Studio output:
10/13 17:22:17: Launching app
No apk changes detected since last installation, skipping installation of D:\Android\Projects\LEDControl\app\build\outputs\apk\app-debug.apk
$ adb shell am force-stop com.example.seth.ledcontrol
$ adb shell am start -n "com.example.seth.ledcontrol/com.example.seth.ledcontrol.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 6987 on device samsung-gt_i9195-02de24f3
I/InstantRun: Instant Run Runtime started. Android package is com.example.seth.ledcontrol, real application class is null.
W/InstantRun: No instant run dex files added to classpath
I/PersonaManager: getPersonaService() name persona_policy
W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
W/dalvikvm: VFY: unable to resolve interface method 15423: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
W/dalvikvm: VFY: unable to resolve interface method 15427: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
W/dalvikvm: VFY: unable to resolve virtual method 658: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
W/dalvikvm: VFY: unable to resolve virtual method 680: Landroid/content/res/TypedArray;.getType (I)I
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
W/dalvikvm: VFY: unable to resolve virtual method 621: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
W/dalvikvm: VFY: unable to resolve virtual method 623: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/Adreno-EGL: <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8960_KK_2.7_RB1__release_AU ()
OpenGL ES Shader Compiler Version: 17.01.12.SPL
Build Date: 03/25/14 Tue
Local Branch:
Remote Branch: quic/kk_2.7_rb1.32
Local Patches: NONE
Reconstruct Branch: NOTHING
D/OpenGLRenderer: Enabling debug mode 0
I/dalvikvm: Total arena pages for JIT: 11
I/dalvikvm: Total arena pages for JIT: 12
cd cannot be piped like that
Why are you not using the full path to the program?
nohup python /home/pi/Desktop/red.py
This has been asked before here and here, but there are not useful answers, so I'll try to be specific: I'm trying to implement Google Cloud Messaging on an app developed using Android Studio 1.2.2. I have installed Google Play Services as explained here, and I implemented the checkPlayServices() method as suggested in this sample:
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
If the device doesn't has Google Play Service or if it is outdated this method should alert the user and provide a button to install/update it easily. I test the app on a Samsung Galaxy S II with Android 4.1.2 with factory settings so it doesn't has an updated Google Play Services. I have confirmed that the GooglePlayServicesUtil.getErrorDialog() method is called, but the dialog doesn't appear. Instead I got the following in the logcat:
06-14 19:19:45.691 10616-10616/? I/dalvikvm﹕ Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
06-14 19:19:45.691 10616-10616/? W/dalvikvm﹕ VFY: unable to resolve virtual method 250: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
06-14 19:19:45.691 10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x00c2
06-14 19:19:45.691 10616-10616/? I/dalvikvm﹕ DexOpt: access denied from Lcom/google/android/gms/common/GooglePlayServicesUtil; to field Landroid/app/Notification;.extras
06-14 19:19:45.691 10616-10616/? W/dalvikvm﹕ VFY: unable to resolve instance field 18
06-14 19:19:45.691 10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x54 at 0x00e1
06-14 19:19:45.691 10616-10616/? E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
06-14 19:19:45.691 10616-10616/? W/dalvikvm﹕ VFY: unable to resolve check-cast 27 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
06-14 19:19:45.691 10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x1f at 0x000e
06-14 19:19:45.696 10616-10616/? I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
06-14 19:19:45.696 10616-10616/? W/dalvikvm﹕ VFY: unable to resolve virtual method 542: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
06-14 19:19:45.696 10616-10616/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000b
06-14 19:19:45.696 10616-10616/? W/GooglePlayServicesUtil﹕ Google Play services out of date. Requires 7571000 but found 2012110
I'm completely stuck. Any help will be appreciated.
Your dialog is not being displayed because execution in the UI thread does not suspend when a dialog is created. This means your application will continue to run after the dialog is supposed to be displayed. If your code does something such as:
showDialog();
startDifferentActivity();
A user wouldn't be able to interact with the dialog because the different activity would start before the dialog even displayed. If you have code execution that is dependent on the user selecting the positive/negative/neutral buttons of a dialog or dismissing a dialog, implement the appropriate listeners.
I am trying to get a NativeActivity app to implement GooglePlayServices. I'm currently trying to do this by creating my own class that extends NativeActivity.
My Google Play services Revision is 18 shown in my Android SDK Manager. I am running on a device that is running Android API 10.
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10"/>
Here is a snippet from my activity
public class KablamActivity extends NativeActivity {
#Override
protected void onResume(){
super.onResume();
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getApplicationContext());
}
}
The following output is saying my Google Play services is out of date as well, but there is supposed to be a dialog popping up telling me something. What do I need to do to resolve the android.app.AlertDialog and android.app.Activity.getFragmentManager issues?
dalvikvm Could not find method android.app.AlertDialog$Builder.<init>, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.a
dalvikvm VFY: unable to resolve direct method 79: Landroid/app/AlertDialog$Builder;.<init> (Landroid/content/Context;I)V
dalvikvm VFY: replacing opcode 0x70 at 0x002c
dalvikvm Could not find method android.app.Activity.getFragmentManager, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.b
dalvikvm VFY: unable to resolve virtual method 28: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
dalvikvm VFY: replacing opcode 0x6e at 0x0023
dalvikvm VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (ILandroid/app/Activity;Landroid/support/v4/app/Fragment;ILandroid/content/DialogInterface$OnCancelListener;)Z
dalvikvm DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
dalvikvm VFY: unable to resolve instance field 53
dalvikvm VFY: replacing opcode 0x52 at 0x0012
dalvikvm VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
GooglePlayServicesUtil Google Play services out of date. Requires 5077000 but found 4452034