Tuesday, June 1, 2021

How to resolve ERROR: In project 'app' a resolved Google Play services library dependency

 

How to resolve ERROR: In project 'app' a resolved Google Play services library dependency











ERROR: In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[16.5.
0]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

Dependency failing: com.google.android.gms:play-services-measurement-api:16.5.0 -> com.google.android.gms:play-services-
measurement-sdk-api@[16.5.0], but play-services-measurement-sdk-api version was 17.0.0.

The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
ifact with the issue.
-- Project 'app' depends onto com.google.android.gms:play-services-ads@18.0.0
-- Project 'app' depends onto com.google.firebase:firebase-analytics@{strictly 16.5.0}
-- Project 'app' depends onto com.google.android.gms:play-services-ads@{strictly 18.0.0}
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-api@{strictly 16.5.0}
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-sdk@{strictly 16.5.0}
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-sdk-api@{strictly 17.0.0}
-- Project 'app' depends onto com.google.firebase:firebase-core@16.0.9
-- Project 'app' depends onto com.google.android.gms:play-services-ads-lite@{strictly 18.0.0}
-- Project 'app' depends onto com.google.firebase:firebase-core@{strictly 16.0.9}

For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b
uild.gradle file.

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.github.dimitrisCBR:GradientTextView:1.2'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.mediarouter:mediarouter:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'dev.dworks.libs:volleyplus:0.1.4'
    implementation 'com.github.clans:fab:1.6.4'
    implementation 'com.github.pedromassango:doubleClick:3.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.6.0'
    implementation project(':library')
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.yarolegovich:discrete-scrollview:1.4.9'
    implementation 'com.github.esafirm.android-image-picker:imagepicker:1.12.0'
    implementation 'jp.wasabeef:glide-transformations:4.0.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.vodyasov:amr:0.5'
    implementation 'org.apache.commons:commons-lang3:3.9'
    implementation 'com.google.guava:guava:26.0-android'
    testImplementation 'junit:junit:4.12'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
    implementation 'com.google.android.exoplayer:exoplayer:2.10.1'
    implementation 'com.squareup:otto:1.3.8'
    implementation 'org.apache.commons:commons-collections4:4.3'
    implementation 'org.greenrobot:eventbus:3.1.1'
    implementation 'io.github.inflationx:calligraphy3:3.1.1'
    implementation 'io.github.inflationx:viewpump:2.0.2'
    implementation 'com.google.android.gms:play-services-ads:18.0.0'
}
apply plugin: 'com.google.gms.google-services'

Wednesday, May 5, 2021

gradle sync failed: could not set process working directory

          gradle sync failed: could not set process working directory

The ProcessBuilder class provides methods for creating and configuring operating system

processes. Each ProcessBuilder instance allows us to manage a collection of process attributes.

We can then start a new Process with those given attributes.

Here are a few common scenarios where we could use this API:

  • Find the current Java version
  • Set-up a custom key-value map for our environment
  • Change the working directory of where our shell command is running
  • Redirect input and output streams to custom replacements
  • Inherit both of the streams of the current JVM process 
  • We'll take a look at practical examples for each of these in later sections.

    But before we dive into the working code, let's take a look at what kind of functionality this API provides.

  • A few important points to keep in mind:

    • The arguments must be in the right order
    • Moreover, in this example, the default working directory and environment are used
    • We deliberately don't call process.waitFor() until after we've read the output because the output buffer might stall the process
    • We've made the assumption that the java command is available via the PATH variable
    • In this next example, we're going to see how to modify the working environment.

      But before we do that let's begin by taking a look at the kind of information we can find in the default environment:

      ProcessBuilder processBuilder = new ProcessBuilder();        
      Map<String, String> environment = processBuilder.environment();
      environment.forEach((key, value) -> System.out.println(key + value));

      This simply prints out each of the variable entries which are provided by default:

      PATH/usr/bin:/bin:/usr/sbin:/sbin
      SHELL/bin/bash
      ...

      Now we're going to add a new environment variable to our ProcessBuilder object and run a command to output its value:

      1. Firstly it shows that upgrade your android version. Target version is not supported.
        [My version was 3.5.3 .After getting this instruction i have upload it to 3.6.2]

      2. Then goes to build and it shows :
        Deprecated Gradle features ware used in this build, make it incompatible with Gradle 7.0

      Beside this IDE Re-commanded for "Android Gradle Plugin is ready to update".

      1. After update the Gradle when goes to build then it takes long time showing "Download bikram-sambat:1.1.0" and after that time shows below error:

      Executing tasks: [:collect_app:assembleDebug] in project blah

      FAILURE: Build failed with an exception.

      • What went wrong:
        Could not determine the dependencies of task ':collect_app:compileDebugJavaWithJavac'.

      Could not resolve all task dependencies for configuration ':collect_app:debugCompileClasspath'.
      Could not resolve bikramsambat:bikram-sambat:1.1.0.
      Required by:
      project :collect_app
      Skipped due to earlier error
      Could not resolve bikramsambat:bikram-sambat:1.1.0.

      build.gradle

      implementation 'org.apache.directory.studio:org.apache.commons.io:2.4
      api group: 'commons-io', name: 'commons-io', version: '2.6'

      Then Sync the build.gradle.
      But still problem exists.

      ERROR:

      collect_app\src\main\java\org\odk\collect\android\activities\FormEntryActivity.java:71: error: cannot find symbol
      import org.apache.commons.io.IOUtils;
      ^

      symbol: class IOUtils 






Friday, April 9, 2021

Xlint:deprecation

 

 Enhanced Deprecation

The semantics of what deprecation means has been clarified, including whether an API could also be removed within the near future.

If you're a library maintainer, you'll cash in of the updated deprecation syntax to tell users of your library about the status of APIs provided by your library.

If you're a library or application developer, you'll use the jdeprscan tool to seek out uses of deprecated JDK API elements in your applications or libraries.

  • Deprecation in the JDK

Deprecation is a notification to library consumers that they should migrate code from a deprecated API.

In the JDK, APIs are deprecated for widely varying reasons, such as:

The API is dangerous (for example, the Thread.stop method).

There is an easy rename (for example, AWT Component.show/hide replaced by setVisible).

A newer, better API can be used instead.

The deprecated API is going to be removed.

In prior releases, APIs were deprecated but virtually never removed. Starting with JDK 9, APIs could also be marked as deprecated for removal. This indicates that the API is eligible to be removed within the next release of the JDK platform. If your application or library consumes any of those APIs, then you ought to make an idea to migrate from them soon.

For an inventory of deprecated APIs within the current release of the JDK, see the Deprecated API page within the API specification.

How to Deprecate APIs

Deprecating an API requires using two different mechanisms: the @Deprecated inpidenc  annotation and the @deprecated Javadoc tag.

The @Deprecated annotation marks an API during a way that's recorded within the class file and is out there at runtime. This allows various tools, like javac and jdeprscan, to detect and flag usage of deprecated APIs. The @deprecated Javadoc tag is employed in documentation of deprecated inpindc  APIs, for instance , to explain the rationale for deprecation, and to suggest alternative APIs.

Note the capitalization: the annotation starts with an uppercase D and therefore the java  Javadoc tag starts with a lowercase d.

Using the @Deprecated Annotation

To indicate deprecation, precede the module, class, method, or member declaration with @Deprecated. The annotation contains these elements:

  • @Deprecated(since="<version>")

    • <version> is the version when the API was deprecated. This is for informational purposes. The default is the empty string ("").

  • @Deprecated(forRemoval=<boolean>)

    • forRemoval=true indicates that the API is subject to removal in a future release.

    • forRemoval=false recommends that code should no longer use this API; however, there is no current intent to remove the API. This is the default value.

For example: @Deprecated(since="9", forRemoval=true)

The @Deprecated annotation causes the Javadoc-generated documentation to be marked with one of the following, wherever that program element appears:
  • Deprecated.

  • Deprecated, for removal: This API element is subject to removal in a future version.

The javadoc tool generates a page named deprecated-list.html which contains the list of deprecated APIs, and adds a link in the navigation bar to that page.

The following is a simple example of using the @Deprecated annotation from the java.lang.Thread class:

public class Thread implements Runnable {
        ... 
        @Deprecated(since="1.2")
        public final void stop() {
                ...
        }
        ...

Semantics of Deprecation

The two elements of the @Deprecated annotation give developers the opportunity to clarify what deprecation means for their exported APIs.

For the JDK platform:
  • @Deprecated(forRemoval=true) indicates that the API is eligible to be removed in a future release of the JDK platform.

  • @Deprecated(since="<version>") contains the JDK version string that indicates when the API element was deprecated, for those deprecated in JDK 9 and beyond.

If you maintain libraries and produce your own APIs, then you probably use the @Deprecated annotation. You should determine and communicate your policy around API removals. For example, if you release a new library every 6 weeks, then you may choose to deprecate an API for removal, but not remove it for several months to give your customers time to migrate.

Using the @deprecated Javadoc Tag

Use the  deprecated inpindec  tag in the javadoc comment of any deprecated program element to indicate that it should no longer be used (even though it may continue to work). This tag is valid altogether class, method, or field documentation comments. The @deprecated indpic  tag must be followed by a space or a newline. In the paragraph following the @deprecated indinc  tag, explain why the item was deprecated, and suggest what to use instead. Mark the text that refers to new versions of an equivalent functionality with an @link tag.

When it encounters an @deprecated tag, the javadoc tool moves the text following the @deprecated tag to the front of the description and precedes it with a warning. For example, this source:

When it encounters an @deprecated tag, the javadoc tool moves the text following the @deprecated tag to the front of the description and precedes it with a warning. For example, this source:
  /**
   * ...
   * @deprecated  This method does not properly convert bytes into
   * characters.  As of JDK 1.1, the preferred way to do this is via the
   * {@code String} constructors that take a {@link
   * java.nio.charset.Charset}, charset name, or that use the platform's
   * default charset.
   * ...
   */
   @Deprecated(since="1.1")
   public String(byte ascii[], int hibyte) {
      ...

generates the following output:

@Deprecated(since="1.1")
public String​(byte[] ascii, 
              int hibyte)
Deprecated. This method does not properly convert bytes into characters. As of 
JDK 1.1, the preferred way to do this is via the String constructors that take a 
Charset, charset name, or that use the platform's default charset.

If you use the @deprecated Javadoc tag without the corresponding @Deprecated annotation, a warning is generated.

Notifications and Warnings

Suppressing inpdinc  Deprecation Warnings

Notifications and Warnings

When an API is deprecated, developers must be notified. The deprecated API may cause problems in your code, or, if it's eventually removed, cause failures at run time.

The Java compiler generates warnings about deprecated APIs. There are options to get more information about warnings, and you'll also suppress deprecation warnings.

Compiler Deprecation Warnings

If the deprecation is forRemoval=false, the Java compiler generates an "ordinary deprecation warning". If the deprecation is forRemoval=true, the compiler generates a "removal warning".

The two kinds of warnings are controlled by separate -Xlint flags: -Xlint:deprecation and -Xlint:removal. The javac -Xlint:removal option is enabled by default, so removal warnings are shown.

The warnings can also be turned off independently (note the "–"): -Xlint:-deprecation and -Xlint:-removal.

This is an example of an ordinary deprecation warning.

$ javac src/example/DeprecationExample.java        
Note: src/example/DeprecationExample.java uses or overrides a deprecated API.   
Note: Recompile with -Xlint:deprecation for details.    

Use the javac -Xlint:deprecation option to see what API is deprecated.

$ javac -Xlint:deprecation src/example/DeprecationExample.java     
src/example/DeprecationExample.java:12: warning: [deprecation] getSelectedValues() in JList has been deprecated 
   Object[] values = jlist.getSelectedValues(); 
                     ^  
1 warning       

Here is an example of a removal warning.

public class RemovalExample {
    public static void main(String[] args) {
        System.runFinalizersOnExit(true);
    }
}
$ javac RemovalExample.java
RemovalExample.java:3: warning: [removal] runFinalizersOnExit(boolean) in System 
has been deprecated and marked for removal
        System.runFinalizersOnExit(true);
              ^
1 warning
==========

Suppressing Deprecation Warnings

The javac -Xlint options control warnings for all indmindec  java files compiled during a particular ad run of javac. You may have identified specific locations in ASCII text file that generate warnings that you simply not want to ascertain . You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled. Place the @SuppressWarnings annotation at the declaration of the category , method, field, or local variable that uses a deprecated API.

The @SuppressWarnings options are:

@SuppressWarnings("deprecation") — Suppresses only the ordinary deprecation warnings.

@SuppressWarnings("removal") — Suppresses only the removal warnings.

@SuppressWarnings({"deprecation","removal"}) — Suppresses both types of warnings.

Here’s an example of suppressing a warning.

@SuppressWarnings("deprecation")

Object[] values = jlist.getSelectedValues();

With the @SuppressWarnings annotation, no warnings are issued for this line, albeit warnings are enabled on the instruction .

Running jdeprscan

jdeprscan may be a static analysis bast  tool that reports on an application’s use of deprecated JDK API elements. Run jdeprscan to assist identify possible issues in compiled class java  files or jar files.

You can determine abou deprecated JDK APIs from the compiler notifications. However, if you don’t recompile with every JDK release, or if the warnings were suppressed, or if you depend upon third-party libraries that are distributed as binary artifacts, then you should run jdeprscan.

It’s important to get dependencies on deprecated APIs before the APIs are faraway from the JDK. If the binary uses an new  API that's deprecated for delete within the current JDK release, and you don’t recompile, then you won’t get any notifications. When the API is removed during a future JDK java  release, then the binary will simply fail at runtime. jdeprscan allows you to detect such usage now, well before the API is delete file .


For the complete syntax of how to run the msol tool and how to interpret the output, see jdeprscan in the Java file  Platform, Standard Edition Tools Reference.

It Usually Begins with javac

While you cannot overlook the very fact that the quality Java compiler javac from Sun includes tons of error checking that's mandated by the Java language, you'll easily miss the very fact that it's a bunch of additional checking that's yours for the asking. Simply add the command-line option -Xlint and you'll see variety of additional warnings. You can optionally append a comma-separated list of categories to the present option, as shown within the "javac Xlint options" table—for example, -Xlint:deprecation,unchecked will run the quality compiler with extra details on use of deprecated code and unchecked type conversions.

Thursday, April 8, 2021

JNI folder in Android Studio

JNI folder in Android Studio

JNI folder in Android Studio


I am trying make helloy-jni app in Android Studio and I have exception


 java.lang.ExceptionInInitializerError
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1319)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
    at android.app.ActivityThread.access$700(ActivityThread.java:154)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5306)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.UnsatisfiedLinkError: Couldn't load hello-jni from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.testjni2-1.apk,libraryPath=/data/app-lib/com.example.testjni2-1]: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
    at java.lang.System.loadLibrary(System.java:535)
    at com.example.testjni2.MainActivity.<clinit>(MainActivity.java:9

I am trying make helloy-jni app in Android Studio and I have exception

06-27 13:17:19.099  12714-12714/com.example.testjni2           E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.ExceptionInInitializerError
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1319)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
    at android.app.ActivityThread.access$700(ActivityThread.java:154)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5306)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.UnsatisfiedLinkError: Couldn't load hello-jni from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.testjni2-1.apk,libraryPath=/data/app-lib/com.example.testjni2-1]: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
    at java.lang.System.loadLibrary(System.java:535)
    at com.example.testjni2.MainActivity.<clinit>(MainActivity.java:9)
    ... 15 more

My structure project looks like this

TestJni2Project

I added my build.gradle line:

   compile files('libs/armeabi/libhello-jni.so')

But this don't helped. I read Gradle and Android Gradle plugin, but I don't find information about working with jni folder

I am thinking what it file dependencies, but it isn't working

My hello-jni.c file includ

jstring  Java_com_example_testjni2_MainActivity_stringFromJNI (JNIEnv *env, jobject thiz){
    return (*env)->NewStringUTF(env, "Hello from JNI !");
  }

My MainActivity file include

public class MainActivity extends Activity {
    static {
        System.loadLibrary("hello-jni");
    }
    public native String  stringFromJNI();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String text = stringFromJNI();
        Log.i("MainActivity", text);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

My Android.mk file containts

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.c

include $(BUILD_SHARED_LIBRARY)

Tell me, please, where I could make a mistake.

Android Studio 0.1.7 OS - Windows 7 x64


While I believe SJoshi (oracle guy) has the most complete answer, the SWIG project is a special case, interesting and useful one, at that, but not generalized for the majority of projects that have done well with the standard SDK ant based projects + NDK. We all would like to be using Android studio now most likely, or want a more CI friendly build toolchain for mobile, which gradle theoretically offers.