Skip to content

Commit

Permalink
[demo]update Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
limpoxe committed Oct 13, 2019
1 parent 6a6637b commit b79f267
Show file tree
Hide file tree
Showing 45 changed files with 253 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -13,4 +13,5 @@ build
build-cache
build-cache.lock
/dump.txt
dump.txt
dump.txt
.cxx
4 changes: 2 additions & 2 deletions Samples/PluginHelloWorld/build.gradle
Expand Up @@ -26,8 +26,8 @@ android {
}

dependencies {
implementation "com.android.support:support-v4:${SUPPORT_VERSION}"
implementation "com.android.support:appcompat-v7:${SUPPORT_VERSION}"
implementation "androidx.legacy:legacy-support-v4:${SUPPORT_VERSION}"
implementation "androidx.appcompat:appcompat:${SUPPORT_VERSION}"
}

//afterEvaluate {
Expand Down
@@ -1,12 +1,10 @@
package com.example.pluginhelloworld;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

/**
* 独立插件测试demo
Expand Down
Expand Up @@ -4,8 +4,8 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand Down
21 changes: 16 additions & 5 deletions Samples/PluginMain/build.gradle
Expand Up @@ -37,11 +37,22 @@ android {
//和splits.abi不能共存
//abiFilters "armeabi-v7a", "x86"
}
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
Expand Down Expand Up @@ -138,16 +149,16 @@ dependencies {

implementation project(':Samples:PluginShareLib')

implementation "com.android.support:design:${SUPPORT_VERSION}"
implementation "com.google.android.material:material:${SUPPORT_VERSION}"

implementation 'com.tencent.bugly:crashreport:2.1.5'
//implementation 'com.umeng.analytics:analytics:latest.integration'

implementation 'org.greenrobot:eventbus:3.0.0'

//Test ButterKnife
implementation 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
}

fairy {
Expand Down
2 changes: 1 addition & 1 deletion Samples/PluginMain/src/main/AndroidManifest.xml
Expand Up @@ -159,7 +159,7 @@
<!--Demo config for plugin AdMob end -->

<provider
android:name="android.support.v4.content.FileProvider"
android:name="androidx.core.content.FileProvider"
android:authorities="a.b.c.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
Expand Down
49 changes: 49 additions & 0 deletions Samples/PluginMain/src/main/cpp/CMakeLists.txt
@@ -0,0 +1,49 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
cxxTest

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
id.h
id.c
CxxTest.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log
libcrypto
libcutils
libselinux)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
cxxTest

# Links the target library to the log library
# included in the NDK.
${log-lib} )
18 changes: 18 additions & 0 deletions Samples/PluginMain/src/main/cpp/CxxTest.cpp
@@ -0,0 +1,18 @@
#include <jni.h>
#include <string>

//在C++代码中调用C的库文件,需加上extern "C",用来告诉编译器:这是一个用C写的库文件,请用C的方式链接它们
extern "C" {
#include "id.h"
}

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_pluginmain_CxxTest_stringFromJNI(
JNIEnv* env,
jobject /* this */) {

whoami();

std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
63 changes: 63 additions & 0 deletions Samples/PluginMain/src/main/cpp/id.c
@@ -0,0 +1,63 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <android/log.h>
//#include <selinux/selinux.h>

#include "id.h"

#define LOG_TAG "whoami"

#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

static void print_uid(uid_t uid)
{
struct passwd *pw = getpwuid(uid);

if(pw) {
LOGV("%d(%s)", uid, pw->pw_name);
} else {
LOGV("%d", uid);
}
}

static void print_gid(gid_t gid)
{
struct group *gr = getgrgid(gid);

if(gr) {
LOGV("%d(%s)", gid, gr->gr_name);
} else {
LOGV("%d", gid);
}
}

int whoami()
{
gid_t list[64];
int n, max;

max = getgroups(64, list);
if (max < 0) max = 0;

LOGV("uid=");
print_uid(getuid());
LOGV(" gid=");
print_gid(getgid());
if (max) {
LOGV(" groups=");
print_gid(list[0]);
for(n = 1; n < max; n++) {
print_gid(list[n]);
}
}
LOGV("\n");
return 0;
}
8 changes: 8 additions & 0 deletions Samples/PluginMain/src/main/cpp/id.h
@@ -0,0 +1,8 @@
#ifndef APF_ID_H
#define APF_ID_H


int whoami();


#endif //APF_ID_H
@@ -0,0 +1,11 @@
package com.example.pluginmain;

public class CxxTest {

public static native String stringFromJNI();

static {
System.loadLibrary("cxxTest");
}

}
@@ -1,7 +1,7 @@
package com.example.pluginmain;

import android.os.Build;
import android.support.annotation.RequiresApi;
import androidx.annotation.RequiresApi;
import android.util.ArrayMap;
import android.util.Log;

Expand Down
Expand Up @@ -3,8 +3,8 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
Expand Down
@@ -1,7 +1,7 @@
package com.example.pluginmain;

import android.Manifest;
import android.arch.lifecycle.Lifecycle;
import androidx.lifecycle.Lifecycle;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
Expand All @@ -11,15 +11,13 @@
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
//import android.provider.BaseColumns;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
Expand Down Expand Up @@ -101,8 +99,8 @@ protected void onCreate(Bundle savedInstanceState) {
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);

Log.e("xx", "infos=" + (infos==null?"0":infos.size()));
Log.e("xx", butterTest.getText().toString());

Log.e("xx", "btnText=" + butterTest.getText().toString());
Log.e("xx", "stringFromJNI " + CxxTest.stringFromJNI());
}

private void initView() {
Expand Down
Expand Up @@ -12,9 +12,9 @@
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand Down
@@ -1,11 +1,10 @@
package com.example.pluginmain;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
Expand Down
@@ -1,7 +1,7 @@
package com.example.pluginmain;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
Expand Down
@@ -1,8 +1,8 @@
package com.example.pluginmain;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
Expand Down
4 changes: 2 additions & 2 deletions Samples/PluginShareLib/build.gradle
Expand Up @@ -28,7 +28,7 @@ android {
}

dependencies {
implementation "com.android.support:support-v4:${SUPPORT_VERSION}"
implementation "com.android.support:appcompat-v7:${SUPPORT_VERSION}"
implementation "androidx.legacy:legacy-support-v4:${SUPPORT_VERSION}"
implementation "androidx.appcompat:appcompat:${SUPPORT_VERSION}"
implementation fileTree(dir: 'libs', include: ['**/**.jar'])
}
@@ -1,7 +1,7 @@
package com.example.pluginsharelib;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;

public class BaseActivity extends AppCompatActivity {

Expand Down

0 comments on commit b79f267

Please sign in to comment.