Adding c++ to the mix

This commit is contained in:
kdeng00
2019-09-26 22:02:09 -04:00
parent 6b68afad9b
commit 356f75d0c5
9 changed files with 299 additions and 128 deletions
+117 -120
View File
File diff suppressed because one or more lines are too long
+19 -7
View File
@@ -19,6 +19,12 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++14"
}
}
} }
buildTypes { buildTypes {
release { release {
@@ -26,22 +32,28 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
} }
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
} }
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50"
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "org.jetbrains.anko:anko:0.10.8" implementation "org.jetbrains.anko:anko:0.10.8"
implementation 'com.ealva:ealvatag:0.4.2' implementation 'com.ealva:ealvatag:0.4.3'
implementation 'com.ealva:ealvalog:0.3.0' implementation 'com.ealva:ealvalog:0.5.0'
implementation 'com.ealva:ealvalog-core:0.3.0' implementation 'com.ealva:ealvalog-core:0.5.0'
implementation 'com.ealva:ealvalog-android:0.3.0' implementation 'com.ealva:ealvalog-android:0.5.0'
implementation 'com.google.guava:guava:20.0' implementation 'com.google.guava:guava:23.0'
implementation 'com.squareup.okio:okio:1.11.0' implementation 'com.squareup.okio:okio:2.4.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
+53
View File
@@ -0,0 +1,53 @@
# 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.
set (HEADERS
model/Song.h
)
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
Demo.cpp
${HEADERS}
)
# 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 )
# 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.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
+37
View File
@@ -0,0 +1,37 @@
//
// Created by brahmix on 9/26/19.
//
#include <iostream>
#include <cstring>
#include <jni.h>
#include <string>
#include <iomanip>
#include <sstream>
#include <fcntl.h>
#include <android/asset_manager_jni.h>
#include <android/log.h>
#include <android/sharedmem.h>
#include <sys/mman.h>
#include "model/Song.h"
int demoCall()
{
model::Song song;
song.title = "hello";
song.artist = "some artist";
std::cout << "testing" << std::endl;
return 0;
}
extern "C"
JNIEXPORT void
JNICALL
Java_com_example_mear_activities_MainActivity_test(
JNIEnv *env,
jobject /* this */) {
demoCall();
}
+25
View File
@@ -0,0 +1,25 @@
//
// Created by brahmix on 9/26/19.
//
#ifndef MEAR_SONG_H
#define MEAR_SONG_H
#include <string>
namespace model {
struct Song
{
int id;
std::string title;
std::string artist;
std::string album;
std::string genre;
int duration;
int year;
};
}
#endif //MEAR_SONG_H
+18
View File
@@ -0,0 +1,18 @@
//
// Created by brahmix on 9/26/19.
//
#ifndef MEAR_USER_H
#define MEAR_USER_H
#include <string>
namespace model {
struct User
{
std::string username;
std::string password;
};
}
#endif //MEAR_USER_H
@@ -53,11 +53,15 @@ class MainActivity : BaseServiceActivity() {
private var repeatOn: Boolean? = false private var repeatOn: Boolean? = false
private var shuffleOn: Boolean? = false private var shuffleOn: Boolean? = false
external fun test()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
test()
permissionPrompt() permissionPrompt()
initialize() initialize()
@@ -407,4 +411,10 @@ class MainActivity : BaseServiceActivity() {
} }
} }
} }
companion object {
init {
System.loadLibrary("native-lib")
}
}
} }
+1 -1
View File
@@ -8,7 +8,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.3.2' classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="mear" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>