Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Dev: fix issue 210 JNI DETECTED ERROR IN APPLICATION: java_class == n…
Browse files Browse the repository at this point in the history
…ul at com.github.druk.dnssd.DNSSD$1.serviceFound(com.github.druk.dnssd.DNSSDService, int, int, byte[], byte[], byte[])

Update Android Gradle Plugin to 7 version
Update target to 31
  • Loading branch information
andriydruk committed Dec 4, 2021
1 parent 1c9d4bd commit 7804cc6
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 37 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "com.github.druk.rxdnssd"
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"
}
Expand All @@ -26,15 +26,15 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

ndkVersion "21.4.7075529"
ndkVersion "23.1.7779620"
}

dependencies {
implementation project(':rx2dnssd')

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'

testImplementation 'junit:junit:4.13.2'
}
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
package="com.github.druk.dnssdsamples">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.github.druk.dnssd.BrowseListener;
import com.github.druk.dnssd.DNSSD;
import com.github.druk.dnssd.DNSSDBindable;
import com.github.druk.dnssd.DNSSDEmbedded;
import com.github.druk.dnssd.DNSSDException;
import com.github.druk.dnssd.DNSSDRegistration;
import com.github.druk.dnssd.DNSSDService;
Expand Down Expand Up @@ -49,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

dnssd = new DNSSDBindable(this);
dnssd = new DNSSDEmbedded(this);

mHandler = new Handler(Looper.getMainLooper());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.github.druk.rx2dnssd.BonjourService;
import com.github.druk.rx2dnssd.Rx2Dnssd;
import com.github.druk.rx2dnssd.Rx2DnssdBindable;
import com.github.druk.rx2dnssd.Rx2DnssdEmbedded;

import java.util.Objects;
Expand All @@ -42,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

rxDnssd = new Rx2DnssdBindable(this);
rxDnssd = new Rx2DnssdEmbedded(this);

findViewById(R.id.check_threads).setOnClickListener(v -> {
/*
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
8 changes: 3 additions & 5 deletions dnssd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0"
}

buildTypes {
Expand All @@ -36,13 +34,13 @@ android {
}
}

ndkVersion "21.4.7075529"
ndkVersion "23.1.7779620"
}

dependencies {
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
// Last version that support Power Mock: https://github.com/powermock/powermock/wiki/Mockito#supported-versions
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-core:4.1.0'
testImplementation ('org.powermock:powermock-api-mockito2:2.0.9') {
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
Expand Down
10 changes: 7 additions & 3 deletions dnssd/src/main/jni/JNISupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ static void DNSSD_API ServiceBrowseReply( DNSServiceRef sdRef _UNUSED, DNSServic

SetupCallbackState( &pContext->Env);

if ( pContext->ClientObj != NULL && pContext->Callback != NULL)
jobject clientObj = (*pContext->Env)->NewLocalRef(pContext->Env, pContext->ClientObj);

if ( clientObj != NULL && pContext->Callback != NULL)
{
if ( errorCode == kDNSServiceErr_NoError)
{
Expand All @@ -363,15 +365,17 @@ static void DNSSD_API ServiceBrowseReply( DNSServiceRef sdRef _UNUSED, DNSServic
(*pContext->Env)->SetByteArrayRegion (pContext->Env, jRegType, 0, (jsize)strlen(regtype), (const jbyte *) regtype);
jbyteArray jReplyDomain = (*pContext->Env)->NewByteArray(pContext->Env, (jsize)strlen(replyDomain));
(*pContext->Env)->SetByteArrayRegion (pContext->Env, jReplyDomain, 0, (jsize)strlen(replyDomain), (const jbyte *) replyDomain);
(*pContext->Env)->CallVoidMethod( pContext->Env, pContext->ClientObj,
(*pContext->Env)->CallVoidMethod( pContext->Env, clientObj,
( flags & kDNSServiceFlagsAdd) != 0 ? pContext->Callback : pContext->Callback2,
pContext->JavaObj, flags, interfaceIndex, jServiceName, jRegType, jReplyDomain);
(*pContext->Env)->DeleteLocalRef( pContext->Env, jServiceName);
(*pContext->Env)->DeleteLocalRef( pContext->Env, jRegType);
(*pContext->Env)->DeleteLocalRef( pContext->Env, jReplyDomain);
}
else
ReportError( pContext->Env, pContext->ClientObj, pContext->JavaObj, errorCode);
ReportError( pContext->Env, clientObj, pContext->JavaObj, errorCode);

(*pContext->Env)->DeleteLocalRef(pContext->Env, clientObj);
}

TeardownCallbackState();
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
10 changes: 4 additions & 6 deletions rx2dnssd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0"
}

buildTypes {
Expand All @@ -33,12 +31,12 @@ dependencies {

// Transitively export that dependencies to other modules
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
api 'io.reactivex.rxjava2:rxjava:2.2.20'
api 'androidx.annotation:annotation:1.1.0'
api 'io.reactivex.rxjava2:rxjava:2.2.21'
api 'androidx.annotation:annotation:1.3.0'

testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
// Last version that support Power Mock: https://github.com/powermock/powermock/wiki/Mockito#supported-versions
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-core:4.1.0'
testImplementation ('org.powermock:powermock-api-mockito2:2.0.9') {
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
Expand Down
8 changes: 3 additions & 5 deletions rxdnssd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0"
}

buildTypes {
Expand All @@ -34,11 +32,11 @@ dependencies {
// Transitively export that dependencies to other modules
api 'io.reactivex:rxandroid:1.2.1'
api 'io.reactivex:rxjava:1.3.8'
api 'androidx.annotation:annotation:1.1.0'
api 'androidx.annotation:annotation:1.3.0'

testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
// Last version that support Power Mock: https://github.com/powermock/powermock/wiki/Mockito#supported-versions
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-core:4.1.0'
testImplementation ('org.powermock:powermock-api-mockito2:2.0.9') {
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
Expand Down

0 comments on commit 7804cc6

Please sign in to comment.